From 39d7f74f37c473160306e750a3e0f95ea27c65d5 Mon Sep 17 00:00:00 2001 From: sev Date: Fri, 25 Oct 2024 18:17:08 -0500 Subject: [PATCH] vim: fix vimrc, remove todo plugin, add lastplace - comments were updated and some sections reordered - removed todo.txt plugin as I have not used it in forever - added lastplace plugin for missing cursor return in nvim - removed vimStartup autocmd from defaults.vim, as lastplace plugin replaces it - made commentary plugin optional and only load under vim, as nvim has built in comment handling now - fix lots of autocmds to use the correct events and actually do things - add autocmd to some options that needed it, such as autoindent under vim - change default colorscheme to murphy - modify space coloration logic and highlight group names - add CTRL-L :noh to vim like with sensible.vim and nvim - add a few new options to override sensible.vim if loaded (like in termux) --- .gitmodules | 8 +- etc/vim/.vimrc | 129 ++++++++++++------ etc/vim/pack/todo.txt-vim/start/todo.txt-vim | 1 - .../{start => opt}/vim-commentary | 0 .../pack/vim-lastplace/start/vim-lastplace | 1 + 5 files changed, 93 insertions(+), 46 deletions(-) delete mode 160000 etc/vim/pack/todo.txt-vim/start/todo.txt-vim rename etc/vim/pack/vim-commentary/{start => opt}/vim-commentary (100%) create mode 160000 etc/vim/pack/vim-lastplace/start/vim-lastplace diff --git a/.gitmodules b/.gitmodules index 761a5e7..42d970b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,11 +1,8 @@ -[submodule "todo.txt-vim"] - path = etc/vim/pack/todo.txt-vim/start/todo.txt-vim - url = https://github.com/freitass/todo.txt-vim [submodule "vim-surround"] path = etc/vim/pack/vim-surround/start/vim-surround url = https://github.com/tpope/vim-surround [submodule "vim-commentary"] - path = etc/vim/pack/vim-commentary/start/vim-commentary + path = etc/vim/pack/vim-commentary/opt/vim-commentary url = https://github.com/tpope/vim-commentary [submodule "vim-speeddating"] path = etc/vim/pack/vim-speeddating/start/vim-speeddating @@ -16,3 +13,6 @@ [submodule "etc/zsh/plugins/evil-registers"] path = etc/zsh/plugins/zshrc/evil-registers url = https://github.com/zsh-vi-more/evil-registers +[submodule "etc/vim/pack/vim-lastplace/start/vim-lastplace"] + path = etc/vim/pack/vim-lastplace/start/vim-lastplace + url = https://github.com/farmergreg/vim-lastplace diff --git a/etc/vim/.vimrc b/etc/vim/.vimrc index 165d01f..6ad6135 100644 --- a/etc/vim/.vimrc +++ b/etc/vim/.vimrc @@ -1,29 +1,17 @@ -""" vim dir in xdg config +""" paths +"" config dir in xdg config let x = ($XDG_CONFIG_HOME??($HOME.'/.config')).'/vim' execute 'set runtimepath='.x.','.&runtimepath.','.x.'/after' execute 'set packpath='.x.','.&packpath.','.x.'/after' -""" vim-only defaults -if !has('nvim') - " neovim defaults are already set - source $VIMRUNTIME/defaults.vim - - " packages - packadd matchit - packadd editorconfig - - " options - set hlsearch - set autoindent -endif - -""" dir for state files in xdg state +"" state files in xdg state let x = ($XDG_STATE_HOME??($HOME.'/.local/state')).'/vim' if !isdirectory(x) call mkdir(x, 'p', 0700) endif -" NOTE: backup files in vim state dir for both vim and neovim +" backup +" NOTE: keep backup files in vim state dir for both vim and neovim let y = x.'/backup' if !isdirectory(y) call mkdir(y, 'p', 0700) @@ -32,21 +20,24 @@ execute 'set backupdir='.y.'//' set backup backupcopy=yes " NOTE: neovim uses ShaDa (SHAred DAta) format for viminfo and swap, and uses a -" different version for undo files, so these types of files when created -" by vim cannot be used with neovim, and the 'viminfofile', 'directory', -" and 'undodir' directories cannot be shared. +" different version of undo file, so these types of files when created by +" vim cannot be used with neovim, and the 'viminfofile', 'directory', and +" 'undodir' directories cannot be shared. " NOTE: neovim has a nice default for these directories and files so " customizing them is not necessary for it. if !has('nvim') + " viminfo " NOTE: 'viminfofile' is a deprecated alias for 'shada' in neovim execute 'set viminfofile='.x.'/.viminfo' + " swap let y = x.'/swap' if !isdirectory(y) call mkdir(y, 'p', 0700) endif execute 'set directory='.y.'//' + " undo let y = x.'/undo' if !isdirectory(y) call mkdir(y, 'p', 0700) @@ -54,35 +45,82 @@ if !has('nvim') execute 'set undodir='.y.'//' endif -autocmd BufNew * set undofile - unlet x unlet y +""" vim-only defaults +if !has('nvim') + " neovim defaults are already set + source $VIMRUNTIME/defaults.vim -""" options -autocmd VimEnter,WinNew * set number -autocmd VimEnter,WinNew * set relativenumber -autocmd InsertEnter * set norelativenumber -autocmd InsertLeave * set relativenumber -autocmd FocusLost * set norelativenumber -autocmd FocusGained * set relativenumber + " disable jumping to last edit, we use vim-lastplace instead + autocmd! vimStartup + " packages + packadd! matchit + packadd! editorconfig " this is now built to [n]vim in but optional + packadd! vim-commentary " nvim has built in commenting now + + " options + set hlsearch + autocmd BufRead * set autoindent +endif + +""" styling +" nice default theme +colorscheme murphy + +" always use color column with less intrusive colors autocmd VimEnter,WinNew * set colorcolumn=80 +" always use cursor line for better visibility autocmd VimEnter,WinNew * set cursorline +" unique highlighting for leading spaces and in-line spaces +" NOTE: this leaves tabs and other special whitespace untouched intentionally +autocmd VimEnter,ColorScheme * highlight Space ctermfg=Grey guifg=#686868 +autocmd VimEnter,ColorScheme * highlight link SpaceLeading NonText +autocmd VimEnter,WinNew * match Space / / +autocmd VimEnter,WinNew * 2match SpaceLeading /\(^ \+\)\|\( \+$\)/ + +" always show statusline +set laststatus=2 + +" truncate > lastline; lastline is nvim default, sensible.vim may also set it +set display=truncate + +" more context while scrolling +set scrolloff=5 +set sidescrolloff=8 + +" show number column on all buffers +autocmd VimEnter,WinNew * set number +" use relative numbers in normal modes when focused, but not if number is off +function! s:SetRelativeNumber(enable) + if !getwinvar(winnr(), '&number') + return + endif + if a:enable + set relativenumber + else + set norelativenumber + endif +endfunction +autocmd InsertEnter,FocusLost,WinLeave * call s:SetRelativeNumber(0) +autocmd VimEnter,WinNew, + \InsertLeave,FocusGained,WinEnter * call s:SetRelativeNumber(1) + +" always show custom listchars autocmd VimEnter,WinNew * set list set listchars=tab:├─,extends:»,precedes:«,space:·,trail:∙,nbsp:■ -""" styles -highlight ColorColumn term=NONE ctermbg=0 - -highlight WhiteSpaceMol ctermfg=Black -autocmd VimEnter,WinNew * match WhiteSpaceMol / / -highlight WhiteSpaceBol ctermfg=DarkBlue -autocmd VimEnter,WinNew * 2match WhiteSpaceBol /\(^ \+\)\|\( \+$\)/ +""" editor +" always save undo file for all file buffers +autocmd BufRead * set undofile -""" indent +"" indent +" always use shiftwidth instead of tabsize +set smarttab +" filetype preferences autocmd FileType python set softtabstop=4 shiftwidth=4 expandtab autocmd FileType markdown set softtabstop=4 shiftwidth=4 expandtab autocmd FileType javascript set softtabstop=2 shiftwidth=2 expandtab @@ -90,17 +128,17 @@ autocmd FileType json set softtabstop=2 shiftwidth=2 expandtab autocmd FileType html set softtabstop=2 shiftwidth=2 expandtab let g:EditorConfig_enable_for_new_buf = 1 -""" syntax +"" syntax autocmd FileType todo set colorcolumn=0 -""" mappings -"" use more accessible escapes, as C-n and C-o are shadowed by some terminals +"" mappings +" use more accessible escapes, as C-n and C-o are shadowed by some terminals if has('nvim') tnoremap n tnoremap o endif -"" move windows any time +" move windows any time if has('nvim') " terminal tnoremap h @@ -118,3 +156,12 @@ nnoremap h nnoremap j nnoremap k nnoremap l + +"" CTRL-L to clear highlighting and also update diff +" NOTE: sensible.vim and nvim already do this, so copy sensible.vim +" functionality if it hasn't been set or we aren't nvim. taken from +" sensible.vim by Tim Pope, under Vim license; see :help license +" https://github.com/tpope/vim-sensible/blob/0ce2d843d6f588bb0c8c7eec6449171615dc56d9/plugin/sensible.vim#L57 +if !has('nvim') && maparg('', 'n') ==# '' + nnoremap :nohlsearch=has('diff')?'diffupdate':'' +endif diff --git a/etc/vim/pack/todo.txt-vim/start/todo.txt-vim b/etc/vim/pack/todo.txt-vim/start/todo.txt-vim deleted file mode 160000 index 3bb5f9c..0000000 --- a/etc/vim/pack/todo.txt-vim/start/todo.txt-vim +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3bb5f9cf0d6c7ee91b476a97054c336104d2b6f5 diff --git a/etc/vim/pack/vim-commentary/start/vim-commentary b/etc/vim/pack/vim-commentary/opt/vim-commentary similarity index 100% rename from etc/vim/pack/vim-commentary/start/vim-commentary rename to etc/vim/pack/vim-commentary/opt/vim-commentary diff --git a/etc/vim/pack/vim-lastplace/start/vim-lastplace b/etc/vim/pack/vim-lastplace/start/vim-lastplace new file mode 160000 index 0000000..e58cb0d --- /dev/null +++ b/etc/vim/pack/vim-lastplace/start/vim-lastplace @@ -0,0 +1 @@ +Subproject commit e58cb0df716d3c88605ae49db5c4741db8b48aa9 -- 2.47.0