Skip to content

Instantly share code, notes, and snippets.

@olimorris
Created March 8, 2021 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olimorris/da15e9a956b55dce259bcc1bac3c9ab5 to your computer and use it in GitHub Desktop.
Save olimorris/da15e9a956b55dce259bcc1bac3c9ab5 to your computer and use it in GitHub Desktop.
------------------------------- NEOVIM SETTINGS --------------------------------
b.autoindent = true
b.expandtab = true -- Use spaces instead of tabs
b.shiftwidth = 4 -- Size of an indent
b.smartindent = true -- Insert indents automatically
b.softtabstop = 4 -- Number of spaces tabs count for
b.tabstop = 4 -- Number of spaces tabs count for
o.backspace = [[indent,eol,start]]
o.clipboard = [[unnamed,unnamedplus]] -- Use the system clipboard
o.completeopt = [[menuone,noinsert,noselect]] -- Completion options for code completion
o.encoding = 'UTF-8' -- Set the encoding type
o.hidden = true -- Enable modified buffers in background
o.history = 1000 -- Remember more stuff
o.hlsearch = true -- Highlight found searches
o.ignorecase = true -- Ignore case
o.incsearch = true -- Shows the match while typing
o.joinspaces = false -- No double spaces with join after a dot
o.lazyredraw = true
o.scrolloff = 5 -- Set the cursor 5 lines down instead of directly at the top of the file
o.sidescrolloff = 8 -- Columns of context
o.shiftround = true -- Round indent
o.showcmd = true -- Show me what I'm typing
o.showmatch = true -- Do not show matching brackets by flickering
o.showmode = false -- Do not show the mode
o.smartcase = true -- Don't ignore case with capitals
o.splitbelow = true -- Put new windows below current
o.splitright = true -- Put new windows right of current
o.termguicolors = true -- True color support
o.wildmode = 'list:longest' -- Command-line completion mode
o.wildignore = [[*/.git/*,*/node_modules/*]] -- Ignore these files/folders
w.colorcolumn = '80' -- Make a ruler at 80px
w.list = true -- Show some invisible characters (tabs...
w.number = true -- Show line number
w.signcolumn = 'yes' -- Show information next to the line numbers
w.wrap = false -- Disable line wrap
o.foldenable = true -- Enable folding
o.foldlevel = 0 -- Fold by default
o.modelines = 1 -- Only use folding settings for this file
o.foldmethod = 'marker' -- Fold based on markers as opposed to indentation
g.neoterm_autoinsert = 1 -- Start terminal in insert mode
g.neoterm_autoscroll = 1 -- Autoscroll the terminal
if fn.isdirectory(fn.stdpath('config')..'/.backup') == 0 then
cmd('call mkdir(stdpath(\'config\').\'/.backup\'), \'p\', 0700')
end
if fn.isdirectory(fn.stdpath('config')..'/.undo') == 0 then
cmd('call mkdir(stdpath(\'config\').\'/.undo\'), \'p\', 0700')
end
if fn.isdirectory(fn.stdpath('config')..'/.swap') == 0 then
cmd('call mkdir(stdpath(\'config\').\'/.swap\'), \'p\', 0700')
end
if fn.isdirectory(fn.stdpath('config')..'/.session') == 0 then
cmd('call mkdir(stdpath(\'config\').\'/.session\'), \'p\', 0700')
end
o.backupdir = fn.stdpath('config')..'/.backup' -- Use backup files
o.directory = fn.stdpath('config')..'/.swap' -- Use Swap files
o.undofile = true -- Maintain undo history between sessions
o.undolevels = 1000 -- Ensure we can undo...a lot
o.undodir = fn.stdpath('config')..'/.undo' -- Set the undo directory
----------------------------------- MAPPINGS -----------------------------------
-- Basic key mappings
g.mapleader = ','
utils.map('n', ';', ':')
utils.map('i', 'jk', '<esc>')
utils.map('n', '<leader>td', ':e todo.txt<cr>', {silent = true})
utils.map('n', '<leader>w', ':w<cr>', {silent = true})
-- Working with init.lua
utils.map('n', '<leader>ev', ':e $MYVIMRC | cd %:p:h<cr>', {silent = true})
utils.map('n', '<leader>sv', ':so $MYVIMRC<cr>', {silent = true})
--noremap <silent><c-C> :call CloseBufferAndPreviewWindows()<cr>
-- Finding and highlighting values
utils.map('n', '<c-f>', ':/')
utils.map('n', '<Leader>f', ':%s///g<Left><Left><Left>')
utils.map('n', '<Leader>h', ':nohlsearch<cr>', {silent = true})
-- Movement
utils.map('n', 'j', 'gj')
utils.map('n', 'k', 'gk')
utils.map('n', 'B', '^')
utils.map('n', 'E', '$')
-- Move lines of code up or down
utils.map('n', '∆', ':m .+1<cr>==')
utils.map('n', '˚', ':m .-2<cr>==')
utils.map('i', '∆', '<Esc>:m .+1<cr>==gi')
utils.map('i', '˚', ':<Esc>m .-2<cr>==gi')
utils.map('v', '∆', ':m \'>+1<cr>gv=gv')
utils.map('v', '˚', ':m \'<-2<cr>gv=gv')
utils.map('v', '<', '<gv') -- Reselect the visual block after indent
utils.map('v', '>', '>gv') -- Reselect the visual block after outdent
-- Splits
utils.map('n', 'sv', ':vsplit<cr>')
utils.map('n', 'sh', ':split<cr>')
utils.map('n', 'sc', '<C-w>q')
utils.map('n', 'so', '<C-w>o') -- Close all splits but the current one
utils.map('n', 'se', '<C-w>=') -- Resize all spltis evenly
utils.map('n', '<C-h>', '<C-w>h') -- Move between splits
utils.map('n', '<C-j>', '<C-w>j') -- Move between splits
utils.map('n', '<C-k>', '<C-w>k') -- Move between splits
utils.map('n', '<C-l>', '<C-w>l') -- Move between splits
-- utils.map('n', '<leader>c', ':only \\| :tabclose<cr>') -- Close all splits and tabs
-- Tabs
utils.map('n', '<leader>tc', ':tabclose<cr>')
utils.map('n', '<leader>to', ':tabonly<cr>')
utils.map('n', '<leader>te', ':tabe %<cr>')
-- Next tab is gt
-- Previous tab is gT
-- Terminal mode
utils.map('t', '<esc>', '<C-\\><C-n>')
utils.map('t', ':q!', '<C-\\><C-n>:q!<cr>')
-- Python
if fn.filereadable('~/.asdf/shims/python2') then
g.python2_host_prog = '~/.asdf/shims/python2'
end
if fn.filereadable('~/.asdf/shims/python3') then
g.python3_host_prog = '~/.asdf/shims/python3'
end
utils.map('n', '<leader>r', ':w!<cr>:<c-u>exec v:count.\'Tclear\'<cr><c-u>exec \'1T python\'.shellescape(\'@%\', 1)<cr>')
-- Misc
utils.map('n', '<leader>so', ':source $MYVIMRC<cr>', {silent = true})
----------------------------------- COMMANDS -----------------------------------
utils.create_augroup({
{ 'CmdlineLeave : echo \'\'' }
}, 'ClearCmdLine')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment