From cec88e90bee57a2de1e9d13d55aa306bb3f15fc8 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Mon, 13 Jan 2020 22:16:53 -0500 Subject: [PATCH] vim: split vimrc into base and 'improved.vim' I had a wild day today debugging a plugin (who will go unnamed) that at one point caused Vim to take 12 seconds to start. Yes. 12 SECONDS. This is the same Vim that can start in < .2 seconds. HOW, you may ask? Let's just say loading automounts from across the globe can be slow. Anyways, this started me on an epic journey to trim my vimrc. See just how minimal I could go. I decided it fit to split my vimrc into just basic settings (which I would want for simple things, like commit messages, prose notes, emails, JSON files, log files, etc). And "improved" settings, for longer coding sessions, where I'm editing large amounts of code, and care about (awesome) features like undo history, mappings, fancy colorschemes, git integration, etc etc. The general idea is to check if the v:progname is "vi" or "[n]vim". If the latter, load "improved", otherwise, remove my ~/.vim from the packpath and keep just the bare necessities. Stay tuned for a bash update to use this... --- vim/improved.vim | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vim/vimrc | 204 ++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 files changed, 166 insertions(+), 176 deletions(-) create mode 100644 vim/improved.vim diff --git a/vim/improved.vim b/vim/improved.vim new file mode 100644 index 0000000..1935395 --- /dev/null +++ b/vim/improved.vim @@ -0,0 +1,138 @@ +" .vim/improved.vim -- putting the IM in VIM + +" GENERAL EDITOR SETTINGS {{{ +" Try to be platform agnostic: +if has('win64') || has('win32') + let s:vimdir = expand($HOME . '/vimfiles') +else + let s:vimdir = expand($HOME . '/.vim') +endif + +" Faster grepping! (use ripgrep if available for :grep and :FZF) +if executable('rg') + set grepprg=rg\ --vimgrep\ --no-heading + set grepformat=%f:%l:%c:%m,%f:%l:%m + let $FZF_DEFAULT_COMMAND = 'rg --files --hidden --glob "!.git/*"' +endif + +" Persistent undo +if has('persistent_undo') && isdirectory(s:vimdir . '/undo') + exe 'set undodir='.s:vimdir.'/undo/' + set undofile " Do indeed create said files + set undolevels=1000 " Max # changes that can be undone + set undoreload=10000 " Saves undofile on reload (:e) if < 10k LOC +endif + +" Use ~/.vim/swp if avail (else .) for backup and swp files respectively +exe 'set backupdir='.s:vimdir.'/swp,.' +exe 'set directory='.s:vimdir.'/swp,.' +" }}} + +" PLUGIN RELATED SETTINGS {{{ +" Don't use powerline font in airline (not neces. installed) +let g:airline_powerline_fonts = 0 + +" This enables folding in the built in markdown ftplugin +let g:markdown_folding = 1 +let g:markdown_fenced_languages = ['sh', 'bash=sh', 'perl', 'python', 'vim'] + +" If using Dirvish, don't use netrw +if isdirectory(s:vimdir . '/pack/plugins/start/vim-dirvish/plugin') + " Dirvish #137 + let loaded_netrwPlugin = 1 +else + let g:netrw_banner=0 " disable banner + let g:netrw_liststyle=1 " details view +endif + +" Mojolicious syntax highlighting for Mojolicious::Lite +let mojo_highlight_data = 1 + +" git-messenger with popup windows is cool! +let g:git_messenger_always_into_popup = v:true +" }}} + +" COLORSCHEME {{{ +" Only gruv if you can handle it +" NOTE: for initial check, check $TERM, not &term, as nvim has &term=nvim +if (($TERM =~# '256color' && has("termguicolors")) || has('gui_running')) && + \ filereadable(s:vimdir . "/pack/mine/start/gruvbox/colors/gruvbox.vim") + + set termguicolors + colorscheme gruvbox + + " See :h xterm-true-color for tmux+termguicolors + if &term =~# '^\(tmux\|st\|screen\)' + let &t_8f = "\[38;2;%lu;%lu;%lum" + let &t_8b = "\[48;2;%lu;%lu;%lum" + endif + + set background=dark + + augroup CurLineToggle + autocmd! + autocmd InsertEnter,InsertLeave * set cul! + augroup END +else + " Can't handle the gruv + set background=light + colorscheme vc +endif +" }}} + +" KEY MAPPINGS {{{ +" set leader to be spacebar +let mapleader = " " + +"Map ctrl-i/j/k/h to switch between splits +nnoremap j +nnoremap k +nnoremap h +nnoremap l + +" Paste from clipboard without any formatting issues +nnoremap :set paste \| put + \| set nopaste + +" Clear trailing whitespace (through regexp) +nnoremap :call vimrc#CMDPreserve("%s/\\s\\+$//e") + +" edit in current buffer dir +nnoremap e :e %:h/ +nnoremap v :vsp %:h/ +nnoremap s :sp %:h/ + +" toggle color column (to ensure short lines) +nnoremap C vimrc#ToggleColorColumn() + +" 2 space / 4 space toggle +nnoremap 2 :setlocal softtabstop=2 shiftwidth=2 +nnoremap 4 :setlocal softtabstop=4 shiftwidth=4 + +" Clear that highlight! +nnoremap :nohlsearch + +" Get greppin quick! --> search word under cursor (escape # for VimL autoload) +nnoremap g :exe "grep " . substitute(expand(''), '#', '\\#', 'g') +nnoremap G :Ggrep! :copen + +" Toggle whitespace +nnoremap w :set list! + +" Yank entire file +nnoremap y :0,$y + + +" Edit vimrc +nnoremap V :edit $HOME/.vim/vimrc + +" From defaults.vim: breaks the undo chain so we can undo +inoremap u +" }}} + +" COMMANDS {{{ +command! CD exe 'cd ' . expand('%:h') +" }}} + +" Load optional config (in ~/.vim) +runtime! .vimrc.local + +" vim:fdm=marker:sts=4:sw=4 diff --git a/vim/vimrc b/vim/vimrc index 6eca629..215b96e 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1,178 +1,30 @@ -" .vimrc by Alex Karle -" Hosted at https://github.com/akarle/dotfiles -" -" Inspired by tips all over the interwebs - -" GENERAL EDITOR SETTINGS {{{ -" Try to be platform agnostic: -if has('win64') || has('win32') - let s:vimdir = expand($HOME . '/vimfiles') -else - let s:vimdir = expand($HOME . '/.vim') -endif - -" Space related -set softtabstop=4 " is 4 spaces (when expandtab set) -set shiftwidth=4 " >> will indent 4 spaces -set expandtab " Needed to replace with spaces -set autoindent " Indent carries over on new line -set smarttab " Use shiftwidth for and - -" Search related -set hlsearch " Highlight searches -set incsearch " Incrementally search - -" Faster grepping! (use ripgrep if available for :grep and :FZF) -if executable('rg') - set grepprg=rg\ --vimgrep\ --no-heading - set grepformat=%f:%l:%c:%m,%f:%l:%m - let $FZF_DEFAULT_COMMAND = 'rg --files --hidden --glob "!.git/*"' -endif - -" Key related behavior -set backspace=indent,eol,start " Backspace should function as expected -set foldopen-=block " {}, (), [] commands don't open folds -set ttimeout " Tell how to interpret key codes (used below) -set ttimeoutlen=30 " Low keycode timeout to avoid delay - -" Other -set belloff=all " Quiet in the Console! -set modelines=0 " Disable modelines for security -set encoding=utf-8 " Encoding -set history=10000 " Remember last 1000 :commands -set scrolloff=5 " Scroll at 5 rows from top/bot of screen -filetype plugin indent on " Enable filetype specific plugins/indent -set tags+=./.vimtags,.vimtags " Look in .vimtags files for ctags - -" Persistent undo -if has('persistent_undo') && isdirectory(s:vimdir . '/undo') - exe 'set undodir='.s:vimdir.'/undo/' - set undofile " Do indeed create said files - set undolevels=1000 " Max # changes that can be undone - set undoreload=10000 " Saves undofile on reload (:e) if < 10k LOC -endif - -" Use ~/.vim/swp if avail (else .) for backup and swp files respectively -exe 'set backupdir='.s:vimdir.'/swp,.' -exe 'set directory='.s:vimdir.'/swp,.' -" }}} - -" PLUGIN RELATED SETTINGS {{{ -" Don't use powerline font in airline (not neces. installed) -let g:airline_powerline_fonts = 0 - -" This enables folding in the built in markdown ftplugin -let g:markdown_folding = 1 -let g:markdown_fenced_languages = ['sh', 'bash=sh', 'perl', 'python', 'vim'] - -" If using Dirvish, don't use netrw -if isdirectory(s:vimdir . '/pack/plugins/start/vim-dirvish/plugin') - " Dirvish #137 - let loaded_netrwPlugin = 1 -else - let g:netrw_banner=0 " disable banner - let g:netrw_liststyle=1 " details view -endif - -" Mojolicious syntax highlighting for Mojolicious::Lite -let mojo_highlight_data = 1 - -" git-messenger with popup windows is cool! -let g:git_messenger_always_into_popup = v:true -" }}} - -" THEME AND APPEARANCE {{{ -syntax on " Syntax highlighting on -set number " Line numbers on -set wildmenu " Visual completion for command mode -set showcmd " Show the command being typed -set laststatus=2 " Always show the statusbar -set noequalalways " Don't resize split on open/close event - -" Whitespace chars to display with :set list -set listchars=space:·,tab:>–,trail:~,eol:¬ - -" COLORSCHEME -" Only gruv if you can handle it -" NOTE: for initial check, check $TERM, not &term, as nvim has &term=nvim -if (($TERM =~# '256color' && has("termguicolors")) || has('gui_running')) && - \ filereadable(s:vimdir . "/pack/mine/start/gruvbox/colors/gruvbox.vim") - - set termguicolors - colorscheme gruvbox - - " See :h xterm-true-color for tmux+termguicolors - if &term =~# '^\(tmux\|st\|screen\)' - let &t_8f = "\[38;2;%lu;%lu;%lum" - let &t_8b = "\[48;2;%lu;%lu;%lum" - endif - - set background=dark - - augroup CurLineToggle - autocmd! - autocmd InsertEnter,InsertLeave * set cul! - augroup END +" .vimrc -- the bare necessities +filetype plugin indent on " Enable filetype plugins/indentation +syntax on " Syntax highlighting on +set softtabstop=4 " is 4 spaces (when expandtab set) +set shiftwidth=4 " >> will indent 4 spaces +set expandtab " Needed to replace with spaces +set autoindent " Indent carries over on new line +set smarttab " Use shiftwidth for and +set hlsearch " Highlight searches +set incsearch " Incrementally search +set backspace=indent,eol,start " Backspace should function as expected +set ttimeout " Timeout on esc keycodes +set ttimeoutlen=30 " Low timeout to avoid delay +set belloff=all " Quiet in the Console! +set modelines=0 " Disable modelines for security +set history=10000 " Remember last 1000 :commands +set scrolloff=3 " Scroll at 3 rows from edge of screen +set number " Line numbers on +set wildmenu " Visual completion for command mode +set showcmd " Show the command being typed +set laststatus=2 " Always show the statusbar +set noequalalways " Don't resize split on open/close event +set listchars=tab:>–,trail:~,eol:$ " Nicer whitespace + +if v:progname =~# 'vim$' + runtime! improved.vim " put the IM in VIM else - " Can't handle the gruv - set background=light - colorscheme vc + set pp-=~/.vim + set pp-=~/.vim/after endif -" }}} - -" KEY MAPPINGS {{{ -" set leader to be spacebar -let mapleader = " " - -"Map ctrl-i/j/k/h to switch between splits -nnoremap j -nnoremap k -nnoremap h -nnoremap l - -" Paste from clipboard without any formatting issues -nnoremap :set paste \| put + \| set nopaste - -" Clear trailing whitespace (through regexp) -nnoremap :call vimrc#CMDPreserve("%s/\\s\\+$//e") - -" edit in current buffer dir -nnoremap e :e %:h/ -nnoremap v :vsp %:h/ -nnoremap s :sp %:h/ - -" toggle color column (to ensure short lines) -nnoremap C vimrc#ToggleColorColumn() - -" 2 space / 4 space toggle -nnoremap 2 :setlocal softtabstop=2 shiftwidth=2 -nnoremap 4 :setlocal softtabstop=4 shiftwidth=4 - -" Clear that highlight! -nnoremap :nohlsearch - -" Get greppin quick! --> search word under cursor (escape # for VimL autoload) -nnoremap g :exe "grep " . substitute(expand(''), '#', '\\#', 'g') -nnoremap G :Ggrep! :copen - -" Toggle whitespace -nnoremap w :set list! - -" Yank entire file -nnoremap y :0,$y + - -" Edit vimrc -nnoremap V :edit $HOME/.vim/vimrc - -" From defaults.vim: breaks the undo chain so we can undo -inoremap u -" }}} - -" COMMANDS {{{ -command! CD exe 'cd ' . expand('%:h') -" }}} - -" Load optional config (in ~/.vim) -runtime! .vimrc.local - -" vim:fdm=marker:sts=4:sw=4 -- libgit2 0.28.4