dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

commit cec88e90bee57a2de1e9d13d55aa306bb3f15fc8 (patch)
parent cd37b178078e05d2cb3d295658abcc2e0320c77f
Author: Alex Karle <alex@karle.co>
Date:   Mon, 13 Jan 2020 22:16:53 -0500

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...

Diffstat:
Avim/improved.vim | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mvim/vimrc | 204+++++++++++--------------------------------------------------------------------
2 files changed, 166 insertions(+), 176 deletions(-)

diff --git a/vim/improved.vim 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 = "\<Esc>[38;2;%lu;%lu;%lum" + let &t_8b = "\<Esc>[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 <C-j> <C-w>j +nnoremap <C-k> <C-w>k +nnoremap <C-h> <C-w>h +nnoremap <C-l> <C-w>l + +" Paste from clipboard without any formatting issues +nnoremap <C-p> :set paste \| put + \| set nopaste<CR> + +" Clear trailing whitespace (through regexp) +nnoremap <leader><space> :call vimrc#CMDPreserve("%s/\\s\\+$//e")<CR> + +" edit in current buffer dir +nnoremap <leader>e :e %:h/ +nnoremap <leader>v :vsp %:h/ +nnoremap <leader>s :sp %:h/ + +" toggle color column (to ensure short lines) +nnoremap <expr> <leader>C vimrc#ToggleColorColumn() + +" 2 space / 4 space toggle +nnoremap <leader>2 :setlocal softtabstop=2 shiftwidth=2<CR> +nnoremap <leader>4 :setlocal softtabstop=4 shiftwidth=4<CR> + +" Clear that highlight! +nnoremap <BS> :nohlsearch<CR> + +" Get greppin quick! --> search word under cursor (escape # for VimL autoload) +nnoremap <leader>g :exe "grep " . substitute(expand('<cword>'), '#', '\\#', 'g')<CR> +nnoremap <silent> <leader>G :Ggrep! <cword><CR>:copen<CR> + +" Toggle whitespace +nnoremap <leader>w :set list!<CR> + +" Yank entire file +nnoremap <leader>y :0,$y +<CR> + +" Edit vimrc +nnoremap <leader>V :edit $HOME/.vim/vimrc<CR> + +" From defaults.vim: breaks the undo chain so we can undo <C-U> +inoremap <C-U> <C-G>u<C-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 @@ -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 " <TAB> is 4 spaces (when expandtab set) -set shiftwidth=4 " >> will indent 4 spaces -set expandtab " Needed to replace <TAB> with spaces -set autoindent " Indent carries over on new line -set smarttab " Use shiftwidth for <TAB> and <BS> - -" 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 <ESC> 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 = "\<Esc>[38;2;%lu;%lu;%lum" - let &t_8b = "\<Esc>[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 " <TAB> is 4 spaces (when expandtab set) +set shiftwidth=4 " >> will indent 4 spaces +set expandtab " Needed to replace <TAB> with spaces +set autoindent " Indent carries over on new line +set smarttab " Use shiftwidth for <TAB> and <BS> +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 <ESC> 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 <C-j> <C-w>j -nnoremap <C-k> <C-w>k -nnoremap <C-h> <C-w>h -nnoremap <C-l> <C-w>l - -" Paste from clipboard without any formatting issues -nnoremap <C-p> :set paste \| put + \| set nopaste<CR> - -" Clear trailing whitespace (through regexp) -nnoremap <leader><space> :call vimrc#CMDPreserve("%s/\\s\\+$//e")<CR> - -" edit in current buffer dir -nnoremap <leader>e :e %:h/ -nnoremap <leader>v :vsp %:h/ -nnoremap <leader>s :sp %:h/ - -" toggle color column (to ensure short lines) -nnoremap <expr> <leader>C vimrc#ToggleColorColumn() - -" 2 space / 4 space toggle -nnoremap <leader>2 :setlocal softtabstop=2 shiftwidth=2<CR> -nnoremap <leader>4 :setlocal softtabstop=4 shiftwidth=4<CR> - -" Clear that highlight! -nnoremap <BS> :nohlsearch<CR> - -" Get greppin quick! --> search word under cursor (escape # for VimL autoload) -nnoremap <leader>g :exe "grep " . substitute(expand('<cword>'), '#', '\\#', 'g')<CR> -nnoremap <silent> <leader>G :Ggrep! <cword><CR>:copen<CR> - -" Toggle whitespace -nnoremap <leader>w :set list!<CR> - -" Yank entire file -nnoremap <leader>y :0,$y +<CR> - -" Edit vimrc -nnoremap <leader>V :edit $HOME/.vim/vimrc<CR> - -" From defaults.vim: breaks the undo chain so we can undo <C-U> -inoremap <C-U> <C-G>u<C-U> -" }}} - -" COMMANDS {{{ -command! CD exe 'cd ' . expand('%:h') -" }}} - -" Load optional config (in ~/.vim) -runtime! .vimrc.local - -" vim:fdm=marker:sts=4:sw=4