From 340fe01281eb3a33c1f13a9685183476cb87f282 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Wed, 9 Aug 2023 14:33:48 -0700 Subject: [PATCH] Simplify vim config --- dot_config/vim/config.vim | 105 +++++++++++++++ dot_config/vim/ftplugin/go.vim.tmpl | 4 +- dot_config/vim/init.d/mappings.vim | 23 ---- dot_config/vim/plug.d/core.vim | 4 - dot_config/vim/plug.d/fzf.vim.tmpl | 9 -- dot_config/vim/plug.d/go.vim.tmpl | 5 - dot_config/vim/plug.d/nerdtree.vim | 30 ----- dot_config/vim/plug.d/rust.vim.tmpl | 5 - dot_config/vim/plug.d/themes.vim | 14 -- .../vim-fancy.vim.tmpl => plug.vim.tmpl} | 38 +++++- dot_config/vim/plugin/autogroup.vim | 4 - dot_config/vim/plugin/commands.vim | 2 - dot_config/vim/plugin/lint.vim | 10 -- dot_config/vim/plugin/theme.vim | 19 --- dot_config/vim/settings.vim.tmpl | 69 ++++++++++ dot_config/vim/vimrc | 18 +-- .../{plugin/settings.vim => workarounds.vim} | 127 +++++------------- dot_config/vim/{init.d => }/xdg.vim | 1 + 18 files changed, 253 insertions(+), 234 deletions(-) create mode 100644 dot_config/vim/config.vim delete mode 100644 dot_config/vim/init.d/mappings.vim delete mode 100644 dot_config/vim/plug.d/core.vim delete mode 100644 dot_config/vim/plug.d/fzf.vim.tmpl delete mode 100644 dot_config/vim/plug.d/go.vim.tmpl delete mode 100644 dot_config/vim/plug.d/nerdtree.vim delete mode 100644 dot_config/vim/plug.d/rust.vim.tmpl delete mode 100644 dot_config/vim/plug.d/themes.vim rename dot_config/vim/{plug.d/vim-fancy.vim.tmpl => plug.vim.tmpl} (57%) delete mode 100644 dot_config/vim/plugin/autogroup.vim delete mode 100644 dot_config/vim/plugin/commands.vim delete mode 100644 dot_config/vim/plugin/lint.vim delete mode 100644 dot_config/vim/plugin/theme.vim create mode 100644 dot_config/vim/settings.vim.tmpl rename dot_config/vim/{plugin/settings.vim => workarounds.vim} (50%) rename dot_config/vim/{init.d => }/xdg.vim (99%) diff --git a/dot_config/vim/config.vim b/dot_config/vim/config.vim new file mode 100644 index 0000000..667ddb1 --- /dev/null +++ b/dot_config/vim/config.vim @@ -0,0 +1,105 @@ +" Mappings +let mapleader="," +let g:mapleader="," + +map rl :source $MYVIMRC +map ss :setlocal spell! +map ts :%s/\s\s*$//g +nnoremap rc :split $MYVIMRC +nnoremap p :set paste +nnoremap np :set nopaste +nnoremap nn :set nonumber norelativenumber +nnoremap rn :set number relativenumber + +" commands +command! W write +command! Q qall! + +" Vim Tabs +map tt :tabnew +map te :tabedit +map tc :tabclose +map to :tabonly +map tn :tabNext +map tp :tabprevious +map tf :tabfirst +map tl :tablast +map tm :tabmove + +" Basics +set encoding=utf-8 + +" General +" setlocal spell spelllang=en_us +set fileformats=unix,dos,mac +set nostartofline +set autochdir +set colorcolumn=81 + +" Have tab complete work more like bash +set wildmode=list:longest +set whichwrap+=<,>,[,] +set magic + +" Turn on omni completion. Must have `filetype plugin on` to use. +" To use, in insert mode press ctrl+x ctrl+o +set omnifunc=syntaxcomplete#Complete +set completeopt=menu,longest,preview + +" Indent +set smartindent +set copyindent +set preserveindent +set shiftround + +" Text Formatting/Layout +set nowrap +set ignorecase +set smartcase +set list + +" UI +set showcmd +set number relativenumber +set numberwidth=4 +set hidden + +" Cues +set showmatch +set matchtime=2 +set hlsearch +set noerrorbells +set novisualbell +set t_vb= +set timeoutlen=500 + +" Tabs +set complete-=i +set autoindent +set backspace=indent,eol,start +set smarttab +set noexpandtab +set shiftwidth=4 +set softtabstop=4 +set tabstop=4 + +set autoread + +" Status +" ~/file [type] [line,column] [number of lines] +"set statusline=%F%m%r%h%w\ [%Y]\ [%03l,%03v]\ [%L] + +set laststatus=2 +set ruler +set wildmenu + +set nrformats-=octal + +set incsearch +set sessionoptions-=options +set viewoptions-=options + +augroup COMMIT_EDITMSG + autocmd! + autocmd BufRead,BufNewFile COMMIT_EDITMSG set filetype=gitcommit +augroup END diff --git a/dot_config/vim/ftplugin/go.vim.tmpl b/dot_config/vim/ftplugin/go.vim.tmpl index 311e8f8..c68f455 100644 --- a/dot_config/vim/ftplugin/go.vim.tmpl +++ b/dot_config/vim/ftplugin/go.vim.tmpl @@ -3,9 +3,9 @@ "{{- if lookPath "go" -}} set noexpandtab -"{{ if lookPath "goimports" -}} +"{{ if lookPath "gofumpt" -}} " use goimports for formatting -let g:go_fmt_command = "goimports" +let g:go_fmt_command = "gofumpt" "{{- end }} " turn highlighting on diff --git a/dot_config/vim/init.d/mappings.vim b/dot_config/vim/init.d/mappings.vim deleted file mode 100644 index 256b2db..0000000 --- a/dot_config/vim/init.d/mappings.vim +++ /dev/null @@ -1,23 +0,0 @@ -" Mappings -let mapleader="," -let g:mapleader="," - -map rl :source $MYVIMRC -map ss :setlocal spell! -map ts :%s/\s\s*$//g -nnoremap rc :split $MYVIMRC -nnoremap p :set paste -nnoremap np :set nopaste -nnoremap nn :set nonumber norelativenumber -nnoremap rn :set number relativenumber - -" Vim Tabs -map tt :tabnew -map te :tabedit -map tc :tabclose -map to :tabonly -map tn :tabNext -map tp :tabprevious -map tf :tabfirst -map tl :tablast -map tm :tabmove diff --git a/dot_config/vim/plug.d/core.vim b/dot_config/vim/plug.d/core.vim deleted file mode 100644 index b5f504b..0000000 --- a/dot_config/vim/plug.d/core.vim +++ /dev/null @@ -1,4 +0,0 @@ -Plug 'bfrg/vim-jq' -Plug 'cespare/vim-toml', { 'for': 'toml' } -Plug 'editorconfig/editorconfig-vim', { 'tag': 'v1.1.1' } -Plug 'tpope/vim-surround', { 'tag': 'v2.2' } diff --git a/dot_config/vim/plug.d/fzf.vim.tmpl b/dot_config/vim/plug.d/fzf.vim.tmpl deleted file mode 100644 index 3ea29d4..0000000 --- a/dot_config/vim/plug.d/fzf.vim.tmpl +++ /dev/null @@ -1,9 +0,0 @@ -" chezmoi:template:left-delimiter="{{ -"{{- /* vim: set filetype=vim: */ -}} -"{{- if lookPath "fzf" -}} -Plug 'junegunn/fzf', { 'tag': '0.40.0' } -Plug 'junegunn/fzf.vim' - -map fz :GFiles -map rg :Rg -"{{- end }} diff --git a/dot_config/vim/plug.d/go.vim.tmpl b/dot_config/vim/plug.d/go.vim.tmpl deleted file mode 100644 index c04e9c7..0000000 --- a/dot_config/vim/plug.d/go.vim.tmpl +++ /dev/null @@ -1,5 +0,0 @@ -" chezmoi:template:left-delimiter="{{ -"{{- /* vim: set filetype=vim: */ -}} -"{{- if lookPath "go" -}} -Plug 'fatih/vim-go' -"{{- end }} diff --git a/dot_config/vim/plug.d/nerdtree.vim b/dot_config/vim/plug.d/nerdtree.vim deleted file mode 100644 index 3dee347..0000000 --- a/dot_config/vim/plug.d/nerdtree.vim +++ /dev/null @@ -1,30 +0,0 @@ -Plug 'preservim/nerdtree', { 'tag': '6.10.16' } - -let g:NERDTreeDirArrowExpandable = '▸' -let g:NERDTreeDirArrowCollapsible = '▾' - -let NERDTreeDirArrows=1 - -map nt :NERDTreeToggle - -" Close nerdtree if it's the last buffer -autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() -\ | quit -\ | endif - -" Mirror nerdtree in each tab -autocmd BufWinEnter * silent NERDTreeMirror - -" check if reading from stdin -autocmd StdinReadPre * let s:std_in=1 - -" open nerdtree if no args in passed to vim -autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | wincmd p | endif - -" open nerdtree if vim opens to a directory -autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') -\ | execute 'NERDTree' argv()[0] -\ | wincmd p -\ | enew -\ | execute 'cd '.argv()[0] -\ | endif diff --git a/dot_config/vim/plug.d/rust.vim.tmpl b/dot_config/vim/plug.d/rust.vim.tmpl deleted file mode 100644 index 85f0333..0000000 --- a/dot_config/vim/plug.d/rust.vim.tmpl +++ /dev/null @@ -1,5 +0,0 @@ -" chezmoi:template:left-delimiter="{{ -"{{- /* vim: set filetype=vim: */ -}} -"{{- if lookPath "rustc" -}} -Plug 'rust-lang/rust.vim', { 'for': 'rust' } -"{{- end }} diff --git a/dot_config/vim/plug.d/themes.vim b/dot_config/vim/plug.d/themes.vim deleted file mode 100644 index 5feb084..0000000 --- a/dot_config/vim/plug.d/themes.vim +++ /dev/null @@ -1,14 +0,0 @@ -Plug 'NLKNguyen/papercolor-theme' -Plug 'joshdick/onedark.vim' -Plug 'morhetz/gruvbox' -Plug 'nanotech/jellybeans.vim', { 'tag': 'v1.7' } -Plug 'romainl/Apprentice' -Plug 'sheerun/vim-wombat-scheme' -Plug 'tomasr/molokai' -Plug 'vim-airline/vim-airline' -Plug 'vim-airline/vim-airline-themes' - -let g:airline_powerline_fonts = 0 -let g:molokai_original = 1 -let g:onedark_hide_endofbuffer = 1 -let g:onedark_terminal_italics = 1 diff --git a/dot_config/vim/plug.d/vim-fancy.vim.tmpl b/dot_config/vim/plug.vim.tmpl similarity index 57% rename from dot_config/vim/plug.d/vim-fancy.vim.tmpl rename to dot_config/vim/plug.vim.tmpl index d61127f..d009f9d 100644 --- a/dot_config/vim/plug.d/vim-fancy.vim.tmpl +++ b/dot_config/vim/plug.vim.tmpl @@ -1,12 +1,38 @@ " chezmoi:template:left-delimiter="{{ "{{- /* vim: set filetype=vim: */ -}} +Plug 'bfrg/vim-jq' +Plug 'editorconfig/editorconfig-vim', { 'tag': 'v1.1.1' } +Plug 'tpope/vim-surround', { 'tag': 'v2.2' } +Plug 'preservim/nerdtree', { 'tag': '6.10.16' } +Plug 'cespare/vim-toml', { 'for': 'toml' } Plug 'SirVer/ultisnips', { 'tag': '3.2' } -let g:UltiSnipsSnippetDirectories = [ 'UltiSnips', 'snips' ] - -"{{ if .development -}} Plug 'lifepillar/pgsql.vim', { 'for': [ 'sql' ] } -let g:sql_type_default = 'pgsql' +" Themes +Plug 'NLKNguyen/papercolor-theme' +Plug 'joshdick/onedark.vim' +Plug 'morhetz/gruvbox' +Plug 'nanotech/jellybeans.vim', { 'tag': 'v1.7' } +Plug 'romainl/Apprentice' +Plug 'sheerun/vim-wombat-scheme' +Plug 'tomasr/molokai' +Plug 'vim-airline/vim-airline' +Plug 'vim-airline/vim-airline-themes' + +"{{ if lookPath "fzf" -}} +Plug 'junegunn/fzf', { 'tag': '0.40.0' } +Plug 'junegunn/fzf.vim' +"{{ end -}} + +"{{ if lookPath "go" }} +Plug 'fatih/vim-go' +"{{ end }} + +"{{ if lookPath "rustc" }} +Plug 'rust-lang/rust.vim', { 'for': 'rust' } +"{{ end }} + +"{{ if .development }} Plug 'dense-analysis/ale', { \ 'tag': 'v3.3.0', \ 'for': [ @@ -38,6 +64,7 @@ Plug 'dense-analysis/ale', { \ ] \ } +"{{ if lookPath "node" }} Plug 'prettier/vim-prettier', { \ 'branch': 'master', \ 'do': 'npm install', @@ -64,4 +91,5 @@ Plug 'prettier/vim-prettier', { \ 'yaml' \ ] \ } -"{{- end }} +"{{ end }} +"{{ end }} diff --git a/dot_config/vim/plugin/autogroup.vim b/dot_config/vim/plugin/autogroup.vim deleted file mode 100644 index 9ed8317..0000000 --- a/dot_config/vim/plugin/autogroup.vim +++ /dev/null @@ -1,4 +0,0 @@ -augroup COMMIT_EDITMSG - autocmd! - autocmd BufRead,BufNewFile COMMIT_EDITMSG set filetype=gitcommit -augroup END diff --git a/dot_config/vim/plugin/commands.vim b/dot_config/vim/plugin/commands.vim deleted file mode 100644 index b87f6f1..0000000 --- a/dot_config/vim/plugin/commands.vim +++ /dev/null @@ -1,2 +0,0 @@ -command! W write -command! Q qall! diff --git a/dot_config/vim/plugin/lint.vim b/dot_config/vim/plugin/lint.vim deleted file mode 100644 index 1729ae6..0000000 --- a/dot_config/vim/plugin/lint.vim +++ /dev/null @@ -1,10 +0,0 @@ -let g:ale_sign_error = '→' -let g:ale_sign_warning = '‽' -let g:ale_echo_msg_format = '%s [%severity%] [%linter%]' -let g:ale_set_loclist = 0 -let g:ale_set_quickfix = 1 - -augroup linters - autocmd! - autocmd FileType javascript let g:ale_linters['javascript'] = ['eslint'] -augroup END diff --git a/dot_config/vim/plugin/theme.vim b/dot_config/vim/plugin/theme.vim deleted file mode 100644 index 4ee708e..0000000 --- a/dot_config/vim/plugin/theme.vim +++ /dev/null @@ -1,19 +0,0 @@ -" Allow color schemes to do bright colors without forcing bold. -if &t_Co == 8 && $TERM !~# '^Eterm' - set t_Co=16 -else - set t_Co=256 -endif - -if (has("nvim")) - let $NVIM_TUI_ENABLE_TRUE_COLOR=1 -endif - -if (has("termguicolors")) - let &t_8f = "\[38;2;%lu;%lu;%lum" - let &t_8b = "\[48;2;%lu;%lu;%lum" - set termguicolors -endif - -colorscheme gruvbox -set background=dark diff --git a/dot_config/vim/settings.vim.tmpl b/dot_config/vim/settings.vim.tmpl new file mode 100644 index 0000000..90599c3 --- /dev/null +++ b/dot_config/vim/settings.vim.tmpl @@ -0,0 +1,69 @@ +" chezmoi:template:left-delimiter="{{ +"{{- /* vim: set filetype=vim: */ -}} +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" fzf +"{{ if lookPath "fzf" }} +Plug 'junegunn/fzf', { 'tag': '0.40.0' } +Plug 'junegunn/fzf.vim' + +map fz :GFiles +map rg :Rg +"{{ end }} + +colorscheme gruvbox +set background=dark + +let g:airline_powerline_fonts = 0 +let g:molokai_original = 1 +let g:onedark_hide_endofbuffer = 1 +let g:onedark_terminal_italics = 1 + +let g:UltiSnipsSnippetDirectories = [ 'UltiSnips', 'snips' ] + +"{{ if .development }} +let g:sql_type_default = 'pgsql' + +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" ALE +let g:ale_sign_error = '→' +let g:ale_sign_warning = '‽' +let g:ale_echo_msg_format = '%s [%severity%] [%linter%]' +let g:ale_set_loclist = 0 +let g:ale_set_quickfix = 1 + +augroup linters + autocmd! + autocmd FileType javascript let g:ale_linters['javascript'] = ['eslint'] +augroup END +"{{ end }} + +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" NERDTree +let g:NERDTreeDirArrowExpandable = '▸' +let g:NERDTreeDirArrowCollapsible = '▾' + +let NERDTreeDirArrows=1 + +map nt :NERDTreeToggle + +" Close nerdtree if it's the last buffer +autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() +\ | quit +\ | endif + +" Mirror nerdtree in each tab +autocmd BufWinEnter * silent NERDTreeMirror + +" check if reading from stdin +autocmd StdinReadPre * let s:std_in=1 + +" open nerdtree if no args in passed to vim +autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | wincmd p | endif + +" open nerdtree if vim opens to a directory +autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') +\ | execute 'NERDTree' argv()[0] +\ | wincmd p +\ | enew +\ | execute 'cd '.argv()[0] +\ | endif diff --git a/dot_config/vim/vimrc b/dot_config/vim/vimrc index 5ed4c80..f82753e 100644 --- a/dot_config/vim/vimrc +++ b/dot_config/vim/vimrc @@ -2,18 +2,12 @@ " The vim help suggests this as the first setting because of the side effects. set nocompatible -" Load from init.d instead of plugin directory. This is done so a leader key -" can be set before loading plugin settings. This allows the plugin setting -" files to set mappings with leader keys -for f in split(glob($XDG_CONFIG_HOME.'/vim/init.d/*.vim'), '\n') - execute 'source '.fnameescape(f) -endfor +source $XDG_CONFIG_HOME/vim/xdg.vim +source $XDG_CONFIG_HOME/vim/config.vim +source $XDG_CONFIG_HOME/vim/workarounds.vim -" The plugged plugin manager function calls need to be called between the -" plug#begin and plug#end. Because of that, using the normal plugin directory -" loading won't work. call plug#begin($XDG_DATA_HOME.'/vim/plugged') -for f in split(glob($XDG_CONFIG_HOME.'/vim/plug.d/*.vim'), '\n') - execute 'source '.fnameescape(f) -endfor +source $XDG_CONFIG_HOME/vim/plug.vim call plug#end() + +source $XDG_CONFIG_HOME/vim/settings.vim diff --git a/dot_config/vim/plugin/settings.vim b/dot_config/vim/workarounds.vim similarity index 50% rename from dot_config/vim/plugin/settings.vim rename to dot_config/vim/workarounds.vim index 2d321ac..845634b 100644 --- a/dot_config/vim/plugin/settings.vim +++ b/dot_config/vim/workarounds.vim @@ -1,3 +1,13 @@ +if (has("nvim")) + let $NVIM_TUI_ENABLE_TRUE_COLOR=1 +endif + +if (has("termguicolors")) + let &t_8f = "\[38;2;%lu;%lu;%lum" + let &t_8b = "\[48;2;%lu;%lu;%lum" + set termguicolors +endif + if has('syntax') && !exists('g:syntax_on') syntax enable endif @@ -7,44 +17,50 @@ if has('autocmd') filetype indent on endif -" Tabs -set complete-=i -set autoindent -set backspace=indent,eol,start -set smarttab -set noexpandtab -set shiftwidth=4 -set softtabstop=4 -set tabstop=4 - -set nrformats-=octal - if !has('nvim') && &ttimeoutlen == -1 set ttimeout set ttimeoutlen=100 endif -set incsearch +if has('path_extra') + setglobal tags-=./tags tags-=./tags; tags^=./tags; +endif + " Use to clear the highlighting of :set hlsearch. if maparg('', 'n') ==# '' nnoremap :nohlsearch=has('diff')?'diffupdate':'' endif -set laststatus=2 -set ruler -set wildmenu +if !empty(&viminfo) + set viminfo^=! +endif -" Status -" ~/file [type] [line,column] [number of lines] -"set statusline=%F%m%r%h%w\ [%Y]\ [%03l,%03v]\ [%L] +if empty(mapcheck('', 'i')) + inoremap u +endif + +if empty(mapcheck('', 'i')) + inoremap u +endif + +if v:version > 703 || v:version == 703 && has("patch541") + set formatoptions+=j " Delete comment character when joining commented lines +endif + +" Allow color schemes to do bright colors without forcing bold. +if &t_Co == 8 && $TERM !~# '^Eterm' + set t_Co=16 +else + set t_Co=256 +endif if !&scrolloff set scrolloff=1 endif + if !&sidescrolloff set sidescrolloff=5 endif -set display+=lastline if &encoding ==# 'latin1' && has('gui_running') set encoding=utf-8 @@ -54,79 +70,10 @@ if &listchars ==# 'eol:$' set listchars=tab:\⇥\ ,trail:…,extends:→,precedes:←,nbsp:+ endif -if v:version > 703 || v:version == 703 && has("patch541") - set formatoptions+=j " Delete comment character when joining commented lines -endif - -if has('path_extra') - setglobal tags-=./tags tags-=./tags; tags^=./tags; -endif - -set autoread - if &history < 10000 set history=10000 endif + if &tabpagemax < 50 set tabpagemax=50 endif -if !empty(&viminfo) - set viminfo^=! -endif -set sessionoptions-=options -set viewoptions-=options - -if empty(mapcheck('', 'i')) - inoremap u -endif - -if empty(mapcheck('', 'i')) - inoremap u -endif - -" Basics -set encoding=utf-8 - -" General -" setlocal spell spelllang=en_us -set fileformats=unix,dos,mac -set nostartofline -set autochdir -set colorcolumn=81 - -" Have tab complete work more like bash -set wildmode=list:longest -set whichwrap+=<,>,[,] -set magic - -" Turn on omni completion. Must have `filetype plugin on` to use. -" To use, in insert mode press ctrl+x ctrl+o -set omnifunc=syntaxcomplete#Complete -set completeopt=menu,longest,preview - -" Indent -set smartindent -set copyindent -set preserveindent -set shiftround - -" Text Formatting/Layout -set nowrap -set ignorecase -set smartcase -set list - -" UI -set showcmd -set number relativenumber -set numberwidth=4 -set hidden - -" Cues -set showmatch -set matchtime=2 -set hlsearch -set noerrorbells -set novisualbell -set t_vb= -set timeoutlen=500 diff --git a/dot_config/vim/init.d/xdg.vim b/dot_config/vim/xdg.vim similarity index 99% rename from dot_config/vim/init.d/xdg.vim rename to dot_config/vim/xdg.vim index 95896c4..1c5978e 100644 --- a/dot_config/vim/init.d/xdg.vim +++ b/dot_config/vim/xdg.vim @@ -1,3 +1,4 @@ +" use XDG if empty($MYVIMRC) | let $MYVIMRC = expand('%:p') | endif if empty($XDG_CACHE_HOME) | let $XDG_CACHE_HOME = $HOME.'/.cache' | endif