Last active
March 21, 2021 04:03
-
-
Save creativenull/9c12fcf8c0dcfe48c5dfca59d86a72af to your computer and use it in GitHub Desktop.
Simple init.lua config converted from init.vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ============================================================================= | |
-- = Utils/Functions = | |
-- ============================================================================= | |
function CursorMode() | |
local mode = vim.fn.mode() | |
if mode == 'n' then | |
return 'NORMAL' | |
elseif mode == 'i' then | |
return 'INSERT' | |
elseif mode == 'c' then | |
return 'COMMAND' | |
elseif mode == 'v' || mode == 'V' || mode == '' then | |
return 'VISUAL' | |
else if mode == 'R' || mode == 'Rv' || mode == 'Rx' then | |
return 'REPLACE' | |
end | |
end | |
function SetExpandTab() | |
vim.bo.expandtab = true | |
end | |
-- Global keymap | |
local function keymap(mode, lhs, rhs, opts) | |
local set_keymap, extend, default_opts = vim.api.nvim_set_keymap, vim.tbl_extend, { noremap = true, silent = true } | |
if opts == nil then set_keymap(mode, lhs, rhs, default_opts) | |
else set_keymap(mode, lhs, rhs, extend('force', default_opts, opts)) end | |
end | |
-- Buffer keymap | |
local function buf_keymap(mode, lhs, rhs, opts) | |
local set_keymap, extend, default_opts = vim.api.nvim_buf_set_keymap, vim.tbl_extend, { noremap = true, silent = true } | |
if opts == nil then set_keymap(mode, lhs, rhs, default_opts) | |
else set_keymap(mode, lhs, rhs, extend('force', default_opts, opts)) end | |
end | |
-- Auto group | |
local function set_augroup(name, cmds) | |
local aucmds = 'augroup ' .. name .. ' au! ' | |
for k, _ in pairs(cmds) do | |
aucmds = aucmds .. k .. ' ' | |
end | |
aucmds = aucmds .. 'augroup end' | |
vim.api.nvim_exec(aucmds, false) | |
end | |
-- ============================================================================= | |
-- = Auto Commands = | |
-- ============================================================================= | |
set_augroup('set_invisible_chars', { | |
'au FileType help set nolist', | |
'au FileType fzf set nolist', | |
}) | |
set_augroup('set_expandtab', { | |
'au BufEnter * :lua SetExpandTab()', | |
}) | |
-- ============================================================================= | |
-- = Plugins = | |
-- ============================================================================= | |
vim.cmd 'packadd packer.nvim' | |
requre 'packer'.startup(function(use) | |
use 'tpope/vim-surround' | |
use 'srcery-colors/srcery-vim' | |
end) | |
-- ============================================================================= | |
-- = Theming and Looks = | |
-- ============================================================================= | |
vim.wo.number = true | |
vim.wo.relativenumber = true | |
vim.o.termguicolors = true | |
vim.cmd 'colorscheme srcery' | |
-- ============================================================================= | |
-- = Options = | |
-- ============================================================================= | |
-- Completion options | |
vim.o.completeopt = 'menuone,noinsert,noselect' | |
vim.o.updatetime = 100 | |
-- Search options | |
vim.o.ignorecase = true | |
vim.o.smartcase = true | |
vim.o.expandtab = true | |
vim.o.wrapscan = true | |
-- Indent options | |
vim.o.tabstop = 4 | |
vim.o.shiftwidth = 0 | |
vim.o.softtabstop = 4 | |
vim.o.smartindent = true | |
-- Line options | |
vim.o.showmatch = true | |
vim.o.showbreak = '+++' | |
vim.o.textwidth = 120 | |
vim.o.scrolloff = 5 | |
vim.wo.linebreak = true | |
vim.wo.colorcolumn = '120' | |
vim.wo.signcolumn = 'yes' | |
-- Move swapfiles and backupfiles into ~/.cache | |
vim.o.swapfile = true | |
vim.o.directory = os.getenv('HOME') .. '/.cache/nvim' | |
vim.o.backup = true | |
vim.o.backupdir = os.getenv('HOME') .. '/.cache/nvim' | |
-- Undo even after closing vim | |
vim.o.undofile = true | |
vim.o.undodir = os.getenv('HOME') .. '/.cache/nvim' | |
vim.o.undolevels = 10000 | |
vim.o.history = 10000 | |
-- Enable a little bit performance | |
vim.o.lazyredraw = true | |
-- Buffers/Tabs/Windows | |
vim.o.hidden = true | |
-- Backspace behaviour | |
vim.o.backspace = indent,eol,start | |
-- Status line | |
vim.o.showmode = false | |
vim.o.statusline = [[ %{luaeval("CursorMode()"} %{expand("%:t")} %m%y %=%l/%L ]] | |
-- Better command display | |
vim.o.cmdheight = 2 | |
vim.wo.list = true | |
vim.o.listchars = [[tab:▸ ,trail:·,space:·]] | |
-- ============================================================================= | |
-- = Keybindings = | |
-- ============================================================================= | |
" Leader key | |
vim.g.mapleader = ' ' | |
" Map Esc, to perform quick switching between Normal and Insert mode | |
keymap('i', 'jk', '<ESC>') | |
" Open built-in file explorer | |
keymap('n', '<F3>', ':Ex<CR>') | |
" Edit vimrc | |
keymap('n', '<leader>ve', ':edit $MYVIMRC<CR>') | |
" Source the vimrc to reflect changes | |
keymap('n', '<leader>vs', ':source $MYVIMRC<CR>') | |
-- ============================================================================= | |
-- = Commands = | |
-- ============================================================================= | |
command! Config edit $MYVIMRC | |
command! ConfigReload source $MYVIMRC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment