summaryrefslogtreecommitdiff
path: root/files/vim/vimrc
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-10-17 12:22:00 -0400
committerAndrew Opalach <andrew@akon.city> 2025-10-17 12:32:42 -0400
commit544da1ba50d9cbf51a18ca0abf1db66b3baa7460 (patch)
tree1caa87664ea4937c5f4e6e8dc83c49b3132ddd70 /files/vim/vimrc
parent85a47287e56ba9100420246531ebea5996cc0486 (diff)
downloaddotfiles-544da1ba50d9cbf51a18ca0abf1db66b3baa7460.tar.gz
dotfiles-544da1ba50d9cbf51a18ca0abf1db66b3baa7460.tar.bz2
dotfiles-544da1ba50d9cbf51a18ca0abf1db66b3baa7460.zip
Gentoo desktop
Diffstat (limited to 'files/vim/vimrc')
-rw-r--r--files/vim/vimrc294
1 files changed, 294 insertions, 0 deletions
diff --git a/files/vim/vimrc b/files/vim/vimrc
new file mode 100644
index 0000000..41e30fb
--- /dev/null
+++ b/files/vim/vimrc
@@ -0,0 +1,294 @@
+" @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\+\%#\@<!$/
+au InsertLeave * match Error /\s\+$/
+
+" Check for SHIFT_JIS.
+set fileencodings=ucs-bom,utf-8,sjis,default,latin1
+
+" 4 spaces autoindent.
+set tabstop=4
+set shiftwidth=4
+set expandtab
+set autoindent
+
+" C syntax preference.
+let g:c_syntax_for_h=1
+let g:c_no_curly_error=1
+let g:c_function_pointers=1
+set cinoptions=:0,=4,l1,g2,h2,(4,u4,+4,m1,j1,J1
+set cindent
+
+" Set different format for mail and text files.
+set nowrap nolinebreak nolist formatoptions=l textwidth=0
+au FileType mail,text setlocal wrap formatoptions=l textwidth=0
+
+" Ex tab complete that makes sense to me.
+set wildmode=longest,list,full
+set wildmenu
+
+" Set titlebar.
+set title
+au BufEnter * let &titlestring=expand("%:t")
+
+" https://github.com/csdvrx/CuteVim/blob/main/.vimrc
+
+" Allow distinguishing <C-i> from <Tab> in bindings.
+" If using vim rather than neovim, this will disable the ability
+" to map <C-h/j/k/l>. 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 = "\<Esc>[>4;2m"
+"let &t_TE = "\<Esc>[>4;m"
+" Treat shift + backspace as normal backspace.
+"noremap <S-BS> <BS>
+
+" 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 <S-h> <nop>
+nnoremap <S-j> <nop>
+nnoremap <S-k> <nop>
+nnoremap <S-l> <nop>
+" Normal mode tab no-op.
+nmap <Tab> <nop>
+" ctrl + c no-op.
+nnoremap <C-c> <nop>
+" Disable F1 for help.
+nmap <F1> <nop>
+" Disable q: for histroy.
+nmap q: <nop>
+" Simplify split movement.
+nnoremap <silent> <C-h> :wincmd h<CR>
+nnoremap <silent> <C-j> :wincmd j<CR>
+nnoremap <silent> <C-k> :wincmd k<CR>
+nnoremap <silent> <C-l> :wincmd l<CR>
+" Make ctrl + "." and "," map to previous buffer.
+nmap <C-,> <C-^>
+nmap <C-.> <C-^>
+" Personally intuitive pop-up menu binds.
+inoremap <expr> <CR> pumvisible() ? "<C-y><CR>" : "<CR>"
+inoremap <expr> <Up> pumvisible() ? "<C-p>" : "<Up>"
+inoremap <expr> <Down> pumvisible() ? "<C-n>" : "<Down>"
+" Ctags
+nnoremap <C-d> <C-]>
+" Toggle colorcolumn.
+nmap <silent> C :exe "set colorcolumn=" . (&colorcolumn == "" ? "101" : "")<CR>
+" Toggle css color highlighting.
+noremap <silent> # :ColorToggle<CR>
+" Buffer select.
+nmap <silent> \ :call QNameInit(1)<CR>:~
+" Git summary.
+nmap <silent> Y :vertical G<CR>
+
+" 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("<args>", "EDIT")
+command -nargs=* -complete=customlist,RelativeFileComplete VS :call OpenBasedOnRelativeArgument("<args>", "VERTICAL_SPLIT")
+command -nargs=* -complete=customlist,RelativeFileComplete S :call OpenBasedOnRelativeArgument("<args>", "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 <expr> e getcmdtype() == ":" && getcmdline() == "e" ? "E" : "e"
+cnoreabbrev <expr> vs getcmdtype() == ":" && getcmdline() == "vs" ? "VS" : "vs"
+cnoreabbrev <expr> s getcmdtype() == ":" && getcmdline() == "s" ? "S" : "s"
+
+" :no -> :nohlsearch instead of :noremap.
+cnoreabbrev <expr> no getcmdtype() == ":" && getcmdline() == "no" ? "nohlsearch" : "no"
+
+call Juliana#Init() " Custom insert mode tab behavior inherited from Emacs.
+inoremap <silent> <Tab> <C-R>=Juliana#CompleteTab("START")<CR>
+ \<C-R>=Juliana#CompleteTab("TAB")<CR>
+ \<C-R>=Juliana#CompleteTab("ALIGN")<CR>
+ \<C-R>=Juliana#CompleteTab("NEXT")<CR>
+inoremap <silent> <S-Tab> <C-R>=Juliana#CompleteSTab("PREV")<CR>
+nnoremap <silent> <expr> <Tab> 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' <q-args>
+command -nargs=+ Ggr execute "silent Ggrep!" <q-args> | botright cwindow | redraw!
+" I had this mapped to <C-i> for the longest time. Sadly with OG vim
+" (not neovim) the fix for mapping <Tab> and <C-i> seperately doesn't work.
+" Changing this bind as the only concession to be compatible with vim
+" seems well worth it.
+nnoremap <C-o> :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()