Last active
March 19, 2021 14:34
-
-
Save creativenull/e7aa618b8f714f6302e2bf382ef7cf9f to your computer and use it in GitHub Desktop.
minimal neovim config file in lua, opinionated of course
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
-- ============================================================================= | |
-- = Plugins = | |
-- ============================================================================= | |
-- Plugin settings that are set with g: variable should be declared BEFORE you load the plugins | |
-- For example: "let g:varname = ..." becomes "vim.g.varname = ..." | |
-- "let g:var#name#with#hash = ..." => "vim.g['var#name#with#hash'] = ..." | |
-- Load the plugins | |
-- Then run any plugin that uses the setup() function | |
-- ============================================================================= | |
-- = Theming and Looks = | |
-- ============================================================================= | |
vim.wo.number = true | |
vim.wo.relativenumber = true | |
vim.o.termguicolors = true | |
-- Uncomment this line and replace <name> with the colorscheme name | |
-- vim.cmd 'colorscheme <name>' | |
-- ============================================================================= | |
-- = Options = | |
-- ============================================================================= | |
-- Completion options | |
vim.o.completeopt = 'menuone,noinsert,noselect' | |
vim.o.shortmess = vim.o.shortmess .. 'c' | |
vim.o.updatetime = 100 | |
-- Search options | |
vim.o.ignorecase = true | |
vim.o.smartcase = true | |
vim.o.wrapscan = true | |
-- Indent options | |
vim.o.tabstop = 4 | |
vim.o.shiftwidth = 0 | |
vim.o.softtabstop = 4 | |
vim.o.expandtab = true | |
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' -- some prefer 80, I just like to break the rules :) | |
-- Move swapfiles and backupfiles to ~/.cache | |
vim.o.directory = os.getenv('HOME') .. '/.cache/nvim' | |
vim.o.backup = true | |
vim.o.backupdir = os.getenv('HOME') .. '/.cache/nvim' | |
-- Enable undo features, even after closing vim | |
vim.o.undofile = true | |
vim.o.undodir = os.getenv('HOME') .. '/.cache/nvim' | |
vim.o.undolevels = 10000 | |
-- Lazy redraw | |
vim.o.lazyredraw = true | |
-- Buffers/Tabs/Windows | |
vim.o.hidden = true | |
-- Set spelling | |
vim.o.spell = false | |
-- For git | |
vim.wo.signcolumn = 'yes' | |
-- Mouse support | |
vim.o.mouse = 'a' | |
-- backspace behaviour | |
vim.o.backspace = 'indent,eol,start' | |
-- Status line | |
vim.o.showmode = false | |
-- Better display | |
vim.o.cmdheight = 2 | |
-- ============================================================================= | |
-- = Keybindings = | |
-- ============================================================================= | |
vim.g.mapleader = ' ' | |
-- Simple function to map keymap, non-recursive way | |
local function map_key(mode, lhs, rhs) | |
vim.api.nvim_set_keymap(mode, lhs, rhs, { noremap = true, silent = true }) | |
end | |
-- Unbind default bindings for arrow keys, trust me this is for your own good | |
map_key('v', '<up>', '<nop>') | |
map_key('v', '<down>', '<nop>') | |
map_key('v', '<left>', '<nop>') | |
map_key('v', '<right>', '<nop>') | |
map_key('i', '<up>', '<nop>') | |
map_key('i', '<down>', '<nop>') | |
map_key('i', '<left>', '<nop>') | |
map_key('i', '<right>', '<nop>') | |
-- Map Esc, to perform quick switching between Normal and Insert mode | |
map_key('i', 'jk', '<ESC>') | |
-- Map escape from terminal input to Normal mode | |
map_key('i', '<ESC>', [[<C-\><C-n>]]) | |
map_key('i', '<C-[>', [[<C-\><C-n>]]) | |
-- Copy/Paste from the system clipboard | |
-- I don't recommend this, so uncomment at your own risk | |
-- map('v', '<C-c>', '"+y<CR>') | |
-- map('n', '<C-v>', '"+p<CR>') | |
-- Open built-in file expolorer | |
map_key('n', '<F3>', ':Ex<CR>') | |
-- Manual completion | |
map_key('i', '<C-Space>', '<C-x><C-o>') | |
-- Disable highlights | |
map_key('n', '<leader><CR>', ':noh<CR>') | |
-- Buffer maps | |
-- You can remap them to any other keys | |
map_key('n', '<leader>bl', ':buffers<CR>') | |
-- Go to next buffer | |
map_key('n', '<C-l>', ':bnext<CR>') | |
-- Go to previous buffer | |
map_key('n', '<C-h>', ':bprevious<CR>') | |
-- Close the current buffer | |
map_key('n', '<leader>bd', ':bp<BAR>sp<BAR>bn<BAR>bd<CR>') | |
-- Resize window panes, we can use those arrow keys | |
-- to help use resize windows - at least we give them some purpose | |
map_key('n', '<up>', ':resize +2<CR>') | |
map_key('n', '<down>', ':resize -2<CR>') | |
map_key('n', '<left>', ':vertical resize -2<CR>') | |
map_key('n', '<right>', ':vertical resize +2<CR>') | |
-- Move a line of text Alt+[j/k] | |
map_key('n', '<M-j>', [[mz:m+<CR>`z]]) | |
map_key('n', '<M-k>', [[mz:m-2<CR>`z]]) | |
map_key('v', '<M-j>', [[:m'>+<CR>`<my`>mzgv`yo`z]]) | |
map_key('v', '<M-k>', [[:m'<-2<CR>`>my`<mzgv`yo`z]]) | |
-- Edit vimrc and gvimrc | |
map_key('n', '<leader>ve', ':e $MYVIMRC<CR>') | |
-- Source the vimrc to reflect changes | |
map_key('n', '<leader>vs', ':luafile $MYVIMRC<CR>') | |
-- Reload file | |
map_key('n', '<leader>r', ':e!<CR>') | |
-- ============================================================================= | |
-- = Commands = | |
-- ============================================================================= | |
vim.cmd 'command! Config edit $MYVIMRC' | |
vim.cmd 'command! ConfigReload luafile $MYVIMRC' | |
-- Don't make mistakes, there are no such thing :) | |
vim.cmd 'command! -nargs=* W w' | |
vim.cmd 'command! -nargs=* Wq wq' | |
vim.cmd 'command! -nargs=* WQ wq' | |
vim.cmd 'command! -nargs=* Q q' | |
vim.cmd 'command! -nargs=* Qa qa' | |
vim.cmd 'command! -nargs=* QA qa' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment