" @TODO: Map 'd' to delete no yank " Basic settings. set nocompatible set number " showmode too often puts the cursor on the bottom line, this can make " kitty's cursor_trail way too jumpy. set noshowmode "set signcolumn=yes set updatetime=250 set scrolloff=5 "set lazyredraw " Don't ask to save changes when switching buffers. set hidden " Use the last buffer instead of the right-most when opening from quickfix. set switchbuf=uselast " Show match count. set shortmess-=S " Old split defaults (I think). set splitright set splitbelow " Stop buffers from jumping when opening buffer selection. set splitkeep=screen set termguicolors colo lil_pablo " Syntax and indent from filetype. filetype plugin indent on syntax on " Search farther and longer to correctly highlight. "au BufEnter * :syntax sync minlines=10 set redrawtime=3000 set maxmempattern=5000 " Highlight unwanted whitespace. au BufEnter * match Error /\s\+$/ au InsertEnter * match Error /\s\+\%#\@ from in bindings. " If using vim rather than neovim, this will disable the ability " to map . Apparently due to vim's lack of "CSI u" " support, according to some issue reports. " https://github.com/vim/vim/issues/10244 "let &t_TI = "\[>4;2m" "let &t_TE = "\[>4;m" " Treat shift + backspace as normal backspace. "noremap " System clipboard on linux. set clipboard=unnamedplus " Session options. set ssop=curdir,skiprtp,blank,buffers,folds,winsize,terminal set vop-=curdir " Move ~/.viminfo. set viminfo+=n~/.vim/viminfo " Session auto save. " https://vim.fandom.com/wiki/Go_away_and_come_back function! SaveSession() if v:this_session != "" echo "Saving." exe "mksession! " . v:this_session else echo "No Session." endif endfunction au VimLeave * :call SaveSession() if isdirectory(expand("~/c")) " Swap file directory. let swap_dir = expand("~/c/sessions/swaps//") if !isdirectory(swap_dir) call mkdir(swap_dir, "p", 0755) endif let &directory=swap_dir if has("persistent_undo") let undo_dir = expand("~/c/sessions/undo//") if !isdirectory(undo_dir) call mkdir(undo_dir, "p", 0755) endif let &undodir=undo_dir set undofile endif " Staggered backups. let backup_dir = "/mnt/store/backup/vim" if !isdirectory(backup_dir) let backup_dir = expand("~/c/sessions/backup//") if !isdirectory(backup_dir) call mkdir(backup_dir, "p", 0755) endif endif let &backupdir=backup_dir set backup endif set autocomplete set complete=.^5,w^5,b^5,u^5 set completeopt=popup " Plugins. let g:fugitive_no_maps = 1 set diffopt+=vertical packadd vim-fugitive packadd vim-gitbranch packadd vim-asciidoc-folding packadd Colorizer "if !empty($NIX_SHELL) "packadd lsp "call LspAddServer([#{ "\ name: 'clangd', "\ filetype: ['c', 'cpp'], "\ path: 'clangd', "\ args: ['--background-index'] "\}]) "endif " Custom statusline. function! StatuslineGit() let l:branchname = gitbranch#name() return strlen(l:branchname) > 0 ? " ".l:branchname." " : " " endfunction function! Statusline() abort let focused = g:statusline_winid == win_getid(winnr()) let status = focused ? "%#StatusLine#" : "%#StatusLineNC#" let status .= "%{StatuslineGit()}" let status .= " %{expand('%:~:.')}" " Explicitly expand to relative file, %f was flaky. let status .= " vim@%{hostname()}" let status .= "%=" let status .= " %y" let status .= " %{&fileencoding}" let status .= "[%{&fileformat}]" let status .= "%3p%%" let status .= " %3l:%-3c" return status endfunction set laststatus=2 " Always show statusline. set statusline=%!Statusline() " Make shift + nav keys no-ops. nnoremap nnoremap nnoremap nnoremap " Normal mode tab no-op. nmap " ctrl + c no-op. nnoremap " Disable F1 for help. nmap " Disable q: for histroy. nmap q: " Simplify split movement. nnoremap :wincmd h nnoremap :wincmd j nnoremap :wincmd k nnoremap :wincmd l " Make ctrl + "." and "," map to previous buffer. nmap nmap " Personally intuitive pop-up menu binds. inoremap pumvisible() ? "" : "" inoremap pumvisible() ? "" : "" inoremap pumvisible() ? "" : "" " Ctags nnoremap " Toggle colorcolumn. nmap C :exe "set colorcolumn=" . (&colorcolumn == "" ? "101" : "") " Toggle css color highlighting. noremap # :ColorToggle " Buffer select. nmap \ :call QNameInit(1):~ " Git summary. nmap Y :vertical G " Relative :e, :vs, and :s. fun OpenBasedOnRelativeArgument(A, CMD) " https://stackoverflow.com/a/14348204 let arg = a:A if arg != "" let arg = (arg[0] == "/" ? arg : resolve(fnamemodify(expand("%:h")."/".arg, ":p"))) endif if a:CMD == "EDIT" exe "edit" arg elseif a:CMD == "VERTICAL_SPLIT" exe "vsplit" arg elseif a:CMD == "SPLIT" exe "split" arg endif endfun command -nargs=* -complete=customlist,RelativeFileComplete E :call OpenBasedOnRelativeArgument("", "EDIT") command -nargs=* -complete=customlist,RelativeFileComplete VS :call OpenBasedOnRelativeArgument("", "VERTICAL_SPLIT") command -nargs=* -complete=customlist,RelativeFileComplete S :call OpenBasedOnRelativeArgument("", "SPLIT") fun RelativeFileComplete(A,L,P) let argpath = fnamemodify(a:A, ":h") if argpath[0] == "~" || argpath[0] == "/" let curpath = "" else let curpath = expand("%:h")."/" endif let argfile = fnamemodify(a:A, ":t") let files = globpath(curpath.argpath, argfile."*", 0, 1) for i in range(0, len(files) - 1) if isdirectory(files[i]) let files[i] = files[i]."/" endif if len(curpath) > 0 let files[i] = substitute(files[i], curpath, "", "") let files[i] = substitute(files[i], "^./", "", "") endif endfor return files endfun " https://stackoverflow.com/a/20564623 cnoreabbrev e getcmdtype() == ":" && getcmdline() == "e" ? "E" : "e" cnoreabbrev vs getcmdtype() == ":" && getcmdline() == "vs" ? "VS" : "vs" cnoreabbrev s getcmdtype() == ":" && getcmdline() == "s" ? "S" : "s" " :no -> :nohlsearch instead of :noremap. cnoreabbrev no getcmdtype() == ":" && getcmdline() == "no" ? "nohlsearch" : "no" call Juliana#Init() " Custom insert mode tab behavior inherited from Emacs. inoremap =Juliana#CompleteTab("START") \=Juliana#CompleteTab("TAB") \=Juliana#CompleteTab("ALIGN") \=Juliana#CompleteTab("NEXT") inoremap =Juliana#CompleteSTab("PREV") nnoremap Juliana#CompleteNTab("FOLD") command Tabify set noexpandtab | %retab! | set expandtab command Untabify set expandtab | %retab! command Hex :%!xxd command Unhex :%!xxd -r " https://stackoverflow.com/a/27721306 "command -nargs=+ Ggr execute 'Ggrep! -q' command -nargs=+ Ggr execute "silent Ggrep!" | botright cwindow | redraw! " I had this mapped to for the longest time. Sadly with OG vim " (not neovim) the fix for mapping and seperately doesn't work. " Changing this bind as the only concession to be compatible with vim " seems well worth it. nnoremap :Ggr "" https://stackoverflow.com/a/37040415 function! SyntaxGroup() let l:s = synID(line("."), col("."), 1) echo synIDattr(l:s, "name") . " -> " . synIDattr(synIDtrans(l:s), "name") endfun command Syn :call SyntaxGroup() " https://vi.stackexchange.com/a/456 function! TrimWhitespace() let l:save = winsaveview() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun command Trim :call TrimWhitespace()