diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-06 15:33:15 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-06 15:33:15 +1200 |
commit | d5b19040fc69f0784f375a7573b3a81decbb2cf5 (patch) | |
tree | bb83ea8e1d00c891ea26e74c0c2a676daae2d08c /vim/vimrc | |
parent | Consolidate .vimrc and .vim/filetype.vim (diff) | |
download | dotfiles-d5b19040fc69f0784f375a7573b3a81decbb2cf5.tar.gz dotfiles-d5b19040fc69f0784f375a7573b3a81decbb2cf5.zip |
Refactor vim/vimrc
Rearranging order where logical, adjust comments, remove line
continuation guard and just join all relevant lines.
Diffstat (limited to 'vim/vimrc')
-rw-r--r-- | vim/vimrc | 299 |
1 files changed, 127 insertions, 172 deletions
@@ -1,9 +1,19 @@ +" Tom Ryder (tejr)'s vimrc: <https://sanctum.geek.nz/cgit/dotfiles.git> +" +" This file is not truly self-contained; it should run without errors on its +" own without the accompanying plugins to which it refers near the end of this +" file, but you'll get errors for some of the leader maps, for example. + " If we're in compatible mode, ensure that the 'C' option that disallows line -" continuations is stripped out, as they're heavily used in this -" configuration for readability; we'll put it back later -if &compatible - let s:cpoptions_save = &cpoptions - set cpoptions-=C +" continuations is stripped out, as they're heavily used in this configuration +" for readability; we'll put it back later. Yes, this is necessary, for +" example if this file is :sourced while &compatible, or if Vim is invoked +" under its other name--we are out there, we ex(1)ist! + +" Use UTF-8 by default wherever possible +if has('multi_byte') + set encoding=utf-8 + scriptencoding utf-8 endif " Use different keys for global and local leaders @@ -12,6 +22,11 @@ if has('eval') let g:maplocalleader = '_' endif +" Load filetype settings, including filetype plugins and indent settings +if has('autocmd') + filetype plugin indent on +endif + " Let me backspace over pretty much anything set backspace= " Allow backspacing over autoindent @@ -42,12 +57,8 @@ if v:version >= 701 endif " Cycle back and forth through buffers. -nnoremap <silent> - \ [b - \ :<C-U>bprevious<CR> -nnoremap <silent> - \ ]b - \ :<C-U>bnext<CR> +nnoremap <silent> [b :<C-U>bprevious<CR> +nnoremap <silent> ]b :<C-U>bnext<CR> " Keep plenty of command and search history, because disk space is cheap set history=2000 @@ -70,20 +81,10 @@ if has('cmdline_info') endif " \d inserts the current local date from date(1) -nnoremap <silent> - \ <Leader>d - \ :<C-U>read !date<CR> -" \D inserts the current UTC date from date(1) -nnoremap <silent> - \ <Leader>D - \ :<C-U>read !date -u<CR> +nnoremap <silent> <Leader>d :<C-U>read !date<CR> -" \m in visual/select mode starts a mail message with the selected lines -vmap <Leader>m <Plug>MailMuttSelected -" \m in normal mode starts a mail message with the current line -nmap <Leader>m <Plug>MailMuttLine -" \M in normal mode starts a mail message with the whole buffer -nmap <Leader>M <Plug>MailMuttBuffer +" \D inserts the current UTC date from date(1) +nnoremap <silent> <Leader>D :<C-U>read !date -u<CR> " Don't try to complete strings from included files, just use the strings in " the open buffers; I'll open the file if I want to complete from it @@ -153,56 +154,14 @@ set shortmess+=x " Don't show whitespace characters or end-of-line characters visually by " default, but make \l toggle between them set nolist -nnoremap <silent> - \ <Leader>l - \ :<C-U>set list! list?<CR> +nnoremap <silent> <Leader>l :<C-U>set list! list?<CR> " Don't show line numbers by default, but \n toggles them set nonumber -nnoremap <silent> - \ <Leader>n - \ :<C-U>set number! number?<CR> - -" Disable most core plugin stuff that I don't use; after/plugin/dist.vim -" clears these variables later -if has('eval') - - " 2html.vim is often useful, so keep that - " matchparen.vim I use constantly - - " I handle versioning plugins manually, and have never used .vba - let g:loaded_getscriptPlugin = 1 - let g:loaded_vimballPlugin = 1 - - " This is what grep, sed, Awk, and Perl are for - let g:loaded_logiPat = 1 - - " ^Z, my dudes - let g:loaded_netrwPlugin = 1 - - " Vim servers? What is this, Emacs? - let g:loaded_rrhelper = 1 - - " System dictionaries plus custom per-machine spell files are fine - let g:loaded_spellfile_plugin = 1 - - " If I want to read a file or a file archived within it I'll decompress or - " unarchive it myself; a text editor should not do this - let g:loaded_gzip = 1 - let g:loaded_tarPlugin = 1 - let g:loaded_zipPlugin = 1 - -endif - -" Load plugins for file types -if has('autocmd') - filetype plugin indent on -endif +nnoremap <silent> <Leader>n :<C-U>set number! number?<CR> " Bind \p to show filetype -nnoremap <silent> - \ <Leader>p - \ :<C-U>set filetype?<CR> +nnoremap <silent> <Leader>p :<C-U>set filetype?<CR> " Use UTF-8 by default wherever possible if has('multi_byte') @@ -229,12 +188,8 @@ set nomodeline " I really like ZZ and ZQ, so I wrote a couple more mappings; ZW forces a " write of the current buffer, but doesn't quit, and ZA forces a write of all " buffers but doesn't quit -nnoremap <silent> - \ ZW - \ :<C-U>write!<CR> -nnoremap <silent> - \ ZA - \ :<C-U>wall!<CR> +nnoremap <silent> ZW :<C-U>write!<CR> +nnoremap <silent> ZA :<C-U>wall!<CR> " Don't assume a number with a leading zero is octal; it's far more likely a " zero-padded decimal, so increment and decrement with ^A and ^X on that basis @@ -244,55 +199,12 @@ set nrformats-=octal " leaders when joining lines silent! set formatoptions+=j -" Show the current formatoptions at a glance -nnoremap <silent> - \ <Leader>f - \ :<C-U>setlocal formatoptions?<CR> - -" Use toggle_option_flag.vim plugin to bind quick toggle actions for some -" 'formatoptions' flags -if has('user_commands') - - " a: Reformat paragraphs to 'textwidth' on all insert or delete operations - nnoremap <silent> - \ <Leader>a - \ :<C-U>ToggleOptionFlagLocal formatoptions a<CR> - - " c: Reformat comments to 'textwidth' - nnoremap <silent> - \ <Leader>c - \ :<C-U>ToggleOptionFlagLocal formatoptions c<CR> - - " j: Delete comment leaders when joining lines - nnoremap <silent> - \ <Leader>j - \ :<C-U>ToggleOptionFlagLocal formatoptions j<CR> - - " t: Reformat non-comment text to 'textwidth' - nnoremap <silent> - \ <Leader>t - \ :<C-U>ToggleOptionFlagLocal formatoptions t<CR> - -endif +" \f shows the current formatoptions at a glance +nnoremap <silent> <Leader>f :<C-U>setlocal formatoptions?<CR> " Match all forms of brackets in pairs (including angle brackets) set matchpairs+=<:> -" Fedora's default environment adds a few auto commands that I don't like, -" including the 'return to previous position in buffer' one; fortunately -" they're nice enough to group the commands, so I can just clear them -if has('autocmd') - augroup fedora - autocmd! - augroup END -endif - -" Add the packaged version of matchit.vim included in the distribution, if -" possible; plugin/macros.vim loads this for older Vims -if has('packages') - silent! packadd! matchit -endif - " Change and delete with C and D both cut off the remainder of the line from " the cursor, but Y yanks the whole line, which is inconsistent (and can be " done with yy anyway); this fixes it so it only yanks the rest of the line @@ -312,22 +224,16 @@ if has('extra_search') " Searching as I enter my pattern, \i toggles this set incsearch - nnoremap <silent> - \ <Leader>i - \ :<C-U>set incsearch! incsearch?<CR> + nnoremap <silent> <Leader>i :<C-U>set incsearch! incsearch?<CR> " Highlight search results, \h toggles this set hlsearch - nnoremap <silent> - \ <Leader>h - \ :<C-U>set hlsearch! hlsearch?<CR> + nnoremap <silent> <Leader>h :<C-U>set hlsearch! hlsearch?<CR> " Pressing ^L will clear highlighting until the next search-related " operation; quite good because the highlighting gets distracting after " you've found what you wanted - nnoremap <silent> - \ <C-L> - \ :<C-U>nohlsearch<CR><C-L> + nnoremap <silent> <C-L> :<C-U>nohlsearch<CR><C-L> endif @@ -336,34 +242,24 @@ if has('spell') " Don't check spelling by default, but bind \s to toggle this set nospell - nnoremap <silent> - \ <Leader>s - \ :<C-U>setlocal spell! spell?<CR> + nnoremap <silent> <Leader>s :<C-U>setlocal spell! spell?<CR> " Use New Zealand English for spelling by default (it's almost identical " to British English), but bind \u to switch to US English and \z to " switch back set spelllang=en_nz - nnoremap <silent> - \ <Leader>u - \ :<C-U>setlocal spelllang=en_us spelllang?<CR> - nnoremap <silent> - \ <Leader>z - \ :<C-U>setlocal spelllang=en_nz spelllang?<CR> + nnoremap <silent> <Leader>u :<C-U>setlocal spelllang=en_us spelllang?<CR> + nnoremap <silent> <Leader>z :<C-U>setlocal spelllang=en_nz spelllang?<CR> endif " Preserve the flags for a pattern when repeating a substitution with &; I " don't really understand why this isn't a default, but there it is -nnoremap <silent> - \ & - \ :<C-U>&&<CR> +nnoremap <silent> & :<C-U>&&<CR> " Same again for visual mode; we use vnoremap rather than xnoremap to stay " compatible with old Vims without doing :execute dances -vnoremap <silent> - \ & - \ :<C-U>&&<CR> +vnoremap <silent> & :<C-U>&&<CR> " Default to no swap files at all, in a way that even ancient/tiny Vims will " understand; the auto_cache_dirs.vim plugin will take care of re-enabling @@ -375,9 +271,11 @@ set noswapfile if has('autocmd') augroup dotfiles_swap_skip autocmd! - autocmd BufNewFile,BufReadPre - \ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/* - \ setlocal noswapfile + autocmd BufNewFile,BufReadPre /tmp/* setlocal noswapfile + autocmd BufNewFile,BufReadPre $TMPDIR/* setlocal noswapfile + autocmd BufNewFile,BufReadPre $TMP/* setlocal noswapfile + autocmd BufNewFile,BufReadPre $TEMP/* setlocal noswapfile + autocmd BufNewFile,BufReadPre */shm/* setlocal noswapfile augroup END endif @@ -451,9 +349,11 @@ if has('persistent_undo') if has('autocmd') augroup dotfiles_undo_skip autocmd! - autocmd BufWritePre - \ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/* - \ setlocal noundofile + autocmd BufWritePre /tmp/* setlocal noundofile + autocmd BufWritePre $TMPDIR/* setlocal noundofile + autocmd BufWritePre $TMP/* setlocal noundofile + autocmd BufWritePre $TEMP/* setlocal noundofile + autocmd BufWritePre */shm/* setlocal noundofile augroup END endif @@ -465,9 +365,11 @@ endif if has('viminfo') && has('autocmd') augroup dotfiles_viminfo_skip autocmd! - autocmd BufNewFile,BufReadPre - \ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/* - \ setlocal viminfo= + autocmd BufNewFile,BufReadPre /tmp/* setlocal viminfo= + autocmd BufNewFile,BufReadPre $TMPDIR/* setlocal viminfo= + autocmd BufNewFile,BufReadPre $TMP/* setlocal viminfo= + autocmd BufNewFile,BufReadPre $TEMP/* setlocal viminfo= + autocmd BufNewFile,BufReadPre */shm/* setlocal viminfo= augroup END endif @@ -498,13 +400,6 @@ set shiftround " despite the noble Steve Losh's exhortations set nojoinspaces -" \x strips trailing whitespace via a custom plugin -nmap <Leader>x <Plug>StripTrailingWhitespace - -" Insert blank lines above and below via a custom plugin -nmap [<Space> <Plug>PutBlankLinesAbove -nmap ]<Space> <Plug>PutBlankLinesBelow - " Configuration for window features if has('windows') @@ -536,9 +431,7 @@ endif " Don't wrap by default, but use \w to toggle it on or off quickly set nowrap -nnoremap <silent> - \ <Leader>w - \ :<C-U>set wrap! wrap?<CR> +nnoremap <silent> <Leader>w :<C-U>set wrap! wrap?<CR> " When wrapping text, if a line is so long that not all of it can be shown on " the screen, show as much as possible anyway; by default Vim fills the left @@ -570,18 +463,80 @@ if has('linebreak') set breakindent endif - " \b toggles copy-pasteable linebreak settings - nmap <Leader>b <Plug>CopyLinebreakToggle +endif + +" Disable most core plugin stuff that I don't use; after/plugin/dist.vim +" clears these variables later +if has('eval') + + " 2html.vim is often useful, so keep that + " matchparen.vim I use constantly + + " I handle versioning plugins manually, and have never used .vba + let g:loaded_getscriptPlugin = 1 + let g:loaded_vimballPlugin = 1 + + " This is what grep, sed, Awk, and Perl are for + let g:loaded_logiPat = 1 + + " ^Z, my dudes + let g:loaded_netrwPlugin = 1 + + " Vim servers? What is this, Emacs? + let g:loaded_rrhelper = 1 + + " System dictionaries plus custom per-machine spell files are fine + let g:loaded_spellfile_plugin = 1 + + " If I want to read a file or a file archived within it I'll decompress or + " unarchive it myself; a text editor should not do this + let g:loaded_gzip = 1 + let g:loaded_tarPlugin = 1 + let g:loaded_zipPlugin = 1 + +endif + +" Insert blank lines above and below via my custom unimpaired.vim rip +nmap [<Space> <Plug>PutBlankLinesAbove +nmap ]<Space> <Plug>PutBlankLinesBelow + +" \b toggles copy-pasteable linebreak settings +nmap <Leader>b <Plug>CopyLinebreakToggle + +" \m in visual/select mode starts a mail message with the selected lines +vmap <Leader>m <Plug>MailMuttSelected +" \m in normal mode starts a mail message with the current line +nmap <Leader>m <Plug>MailMuttLine +" \M in normal mode starts a mail message with the whole buffer +nmap <Leader>M <Plug>MailMuttBuffer + +" \x strips trailing whitespace via a custom plugin +nmap <Leader>x <Plug>StripTrailingWhitespace + +" Use toggle_option_flag.vim plugin to bind quick toggle actions for some +" 'formatoptions' flags +if has('user_commands') + + " \a: Reformat paragraphs to 'textwidth' on all insert or delete operations + nnoremap <silent> <Leader>a :<C-U>ToggleOptionFlagLocal formatoptions a<CR> + + " \c: Reformat comments to 'textwidth' + nnoremap <silent> <Leader>c :<C-U>ToggleOptionFlagLocal formatoptions c<CR> + + " \j: Delete comment leaders when joining lines + nnoremap <silent> <Leader>j :<C-U>ToggleOptionFlagLocal formatoptions j<CR> + + " \t: Reformat non-comment text to 'textwidth' + nnoremap <silent> <Leader>t :<C-U>ToggleOptionFlagLocal formatoptions t<CR> endif +" Add the packaged version of matchit.vim included in the distribution, if +" possible; plugin/macros.vim loads this for older Vims +if has('packages') + silent! packadd! matchit +endif + " Source all .vim files from ~/.vim/config, which may override any of the " above runtime! config/*.vim - -" If we're in compatible mode, put 'cpoptions' back the way we found it at the -" start of this configuration, even though it's the current year -if exists('s:cpoptions_save') - let &cpoptions = s:cpoptions_save - unlet s:cpoptions_save -endif |