From 1c5dec8486ad0cbd2d3547b8f32b44d59b1765fd Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 20 Jun 2018 23:56:16 +1200 Subject: Reorder .vimrc file Put options up the top, starting with core ones and then feature-dependent ones, in alphabetical order, then mappings, then digraphs, then plugin-specific settings. --- vim/vimrc | 372 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 178 insertions(+), 194 deletions(-) (limited to 'vim') diff --git a/vim/vimrc b/vim/vimrc index 0fd8c192..721e6af6 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -10,17 +10,9 @@ if has('multi_byte') scriptencoding utf-8 endif -" Use different keys for global and local leaders -if 1 - let g:mapleader = '\' - let g:maplocalleader = '_' -endif - " Load filetype-specific plugins, indent settings, and syntax highlighting -" Bind \p to show filetype at a glance if has('autocmd') filetype plugin indent on - nnoremap p :set filetype? endif " Options dependent on the syntax feature @@ -42,67 +34,62 @@ if has('syntax') && !has('g:syntax_on') endif +" The all-important default indent settings; filetypes to tweak +set autoindent " Use indent of previous line on new lines +set expandtab " Use spaces instead of tabs +set shiftround " Round indenting to multiples of 4 +set shiftwidth=4 " Indent with four spaces +set softtabstop=4 " Insert four spaces for a Tab press + " Let me backspace over pretty much anything set backspace= set backspace+=indent " Spaces from 'audoindent' set backspace+=eol " Line breaks set backspace+=start " The start of current insertion -" Cycle back and forth through buffers. -nnoremap [b :bprevious -nnoremap ]b :bnext - -" Always tell me the number of lines changed by a command -set report=0 +" Start with blank comment strings rather than the old default; let the +" filetype handle it +set comments= -" Show my current position in the status bar, default format is fine -if has('cmdline_info') - set ruler -endif +" 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 +" column with @ symbols instead, which I don't find very helpful +set display=lastline -" Current date and time insertion commands, requiring POSIX date(1) -if has('unix') - " \d: Local - nnoremap d :read !date - " \D: UTC - nnoremap D :read !date -u +" Try to set the 'j' flag for 'formatoptions', to automatically delete comment +" leaders when joining lines, if supported +if v:version >= 704 || v:version == 703 && has('patch541') + set formatoptions+=j endif -" Start with blank comment strings rather than the old default; let the -" filetype handle it -set comments= +" Don't join lines with two spaces at the end of sentences; I don't two-space, +" despite the noble Steve Losh's exhortations +set nojoinspaces -" Configuration for the command completion feature; rather than merely cycling -" through possible completions with Tab, show them above the command line -if has('wildmenu') +" Define list characters +set listchars+=extends:> " Unwrapped text to screen right +set listchars+=precedes:< " Unwrapped text to screen left +set listchars+=tab:>- " Tab characters, preserve width +set listchars+=trail:_ " Trailing spaces - " Use the wild menu, both completing and showing all possible completions - " with a single Tab press, just as I've configured Bash to do - set wildmenu - set wildmode=list:longest +" Add angle brackets to pairs of characters to match +set matchpairs+=<:> - " Don't complete certain files that I'm not likely to want to manipulate - " from within Vim: - if has('wildignore') - set wildignore+=*.a,*.o - set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png - set wildignore+=.DS_Store,.git,.hg,.svn - set wildignore+=*~,*.swp,*.tmp - endif +" Don't use modelines at all, they're apparently potential security problems +" and I've never used them anyway +set nomodeline - " Complete files without case sensitivity, if the option is available - if exists('+wildignorecase') - set wildignorecase - endif +" 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 +set nrformats-=octal -endif +" Always tell me the number of lines changed by a command +set report=0 -" A few very important custom digraphs -if has('digraphs') - digraph ./ 8230 " Ellipsis (HORIZONTAL ELLIPSIS U+2026) - digraph %% 8984 " Mac command key (PLACE OF INTEREST SIGN U+2318) - digraph 8: 9731 " Snowman (SNOWMAN U+2603) -endif +" Don't bother drawing the screen while executing macros or other automated or +" scripted processes, just draw the screen as it is when the operation +" completes +set lazyredraw " Set up short message settings set shortmess= @@ -120,127 +107,84 @@ set shortmess+=T " Truncate other message in midle if too long set shortmess+=w " written -> [w], appended -> [a] set shortmess+=x " [dos format] -> [dos] -" \l toggles showing tab, end-of-line, and trailing whitespace -nnoremap l :set list! list? - -" \n toggles line numbers -nnoremap n :set number! number? - -" Use all ancestors of current directory for :find -if has('file_in_path') - set path+=** -endif - -" Don't use modelines at all, they're apparently potential security problems -" and I've never used them anyway -set nomodeline +" 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 +" this with a 'directory' setting +set noswapfile -" 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 ZW :write! -nnoremap ZA :wall! +" Never use any kind of bell, visual or not +set visualbell t_vb= -" 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 -set nrformats-=octal +" Don't wrap by default, but use \w to toggle it on or off +set nowrap -" Try to set the 'j' flag for 'formatoptions', to automatically delete comment -" leaders when joining lines, if supported -if v:version >= 704 || v:version == 703 && has('patch541') - set formatoptions+=j +" Show my current position in the status bar, default format is fine +if has('cmdline_info') + set ruler endif -" \f shows the current formatoptions at a glance -nnoremap f :setlocal formatoptions? - -" Add angle brackets to pairs of characters to match -set matchpairs+=<:> - -" 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 -nnoremap Y y$ +" Highlight settings for search, if available +if has('extra_search') + set incsearch " Show matches as I type + set hlsearch " Highlight completed searches +endif -" Rebind in normal mode as a lazy scroll -nnoremap +" Use all ancestors of current directory for :find +if has('file_in_path') + set path+=** +endif -" Some special settings for searching, if available -if has('extra_search') +" Line break settings and mappings +if has('linebreak') - " Searching as I enter my pattern, \i toggles this - set incsearch - nnoremap i :set incsearch! incsearch? + " Break lines at word boundaries if possible + set linebreak - " Highlight search results, \h toggles this - set hlsearch - nnoremap h :set hlsearch! hlsearch? + " Precede continued lines with '...' + set showbreak=... - " 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 :nohlsearch + " If we have the option, indent wrapped lines as much as the first line + if exists('+breakindent') + set breakindent + endif endif -" Configure spell checking features, if available +" Use NZ english by default if has('spell') - - " \s toggles spell checking - nnoremap s :setlocal spell! spell? - - " 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 u :setlocal spelllang=en_us spelllang? - nnoremap z :setlocal spelllang=en_nz spelllang? - 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 & :&& - -" Same again for visual mode; we use vnoremap rather than xnoremap to stay -" compatible with old Vims without doing :execute dances -vnoremap & :&& - -" 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 -" this with a 'directory' setting -set noswapfile - -" Press F10 to stop console Vim from formatting pasted text -set pastetoggle= - -" Don't bother drawing the screen while executing macros or other automated or -" scripted processes, just draw the screen as it is when the operation -" completes -set lazyredraw - -" Never use any kind of bell, visual or not -set visualbell t_vb= - -" Rebind Ctrl-C in insert mode to undo the current insert operation -inoremap u - " When in visual block mode, let me move the cursor anywhere in the buffer; " don't restrict me only to regions with text if has('virtualedit') set virtualedit+=block endif -" The all-important default indent settings; filetypes to tweak -set autoindent " Use indent of previous line on new lines -set expandtab " Use spaces instead of tabs -set shiftround " Round indenting to multiples of 4 -set shiftwidth=4 " Indent with four spaces -set softtabstop=4 " Insert four spaces for a Tab press +" Configuration for the command completion feature; rather than merely cycling +" through possible completions with Tab, show them above the command line +if has('wildmenu') -" Don't join lines with two spaces at the end of sentences; I don't two-space, -" despite the noble Steve Losh's exhortations -set nojoinspaces + " Use the wild menu, both completing and showing all possible completions + " with a single Tab press, just as I've configured Bash to do + set wildmenu + set wildmode=list:longest + + " Don't complete certain files that I'm not likely to want to manipulate + " from within Vim: + if has('wildignore') + set wildignore+=*.a,*.o + set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png + set wildignore+=.DS_Store,.git,.hg,.svn + set wildignore+=*~,*.swp,*.tmp + endif + + " Complete files without case sensitivity, if the option is available + if exists('+wildignorecase') + set wildignorecase + endif + +endif " Configuration for window features if has('windows') @@ -262,20 +206,33 @@ if has('windows') endif -" Don't wrap by default, but use \w to toggle it on or off -set nowrap -nnoremap w :set wrap! wrap? +" Rebind Ctrl-C in insert mode to undo the current insert operation +inoremap u -" 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 -" column with @ symbols instead, which I don't find very helpful -set display=lastline +" Rebind in normal mode as a lazy scroll +nnoremap -" Define list characters -set listchars+=extends:> " Unwrapped text to screen right -set listchars+=precedes:< " Unwrapped text to screen left -set listchars+=tab:>- " Tab characters, preserve width -set listchars+=trail:_ " Trailing spaces +" Preserve the flags for a pattern when repeating a substitution with & +nnoremap & :&& +vnoremap & :&& + +" Pressing ^L will clear highlighting until the next search-related operation +nnoremap :nohlsearch + +" Cycle through things with unimpaired.vim-style bindings: +" Buffers +nnoremap [b :bprevious +nnoremap ]b :bnext +" Quicklist items (more often :helpgrep results) +nnoremap [c :cprevious +nnoremap ]c :cnext +" Location list items +nnoremap [l :lprevious +nnoremap ]l :lnext + +" Insert blank lines above and below via my custom unimpaired.vim rip +nmap [ PutBlankLinesAbove +nmap ] PutBlankLinesBelow " Swap the j/gj and k/gk command pairs so that we move by screen row, not " buffer line, with j/k @@ -284,20 +241,69 @@ nnoremap k gk nnoremap gj j nnoremap gk k -" Line break settings and mappings -if has('linebreak') +" 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 +nnoremap Y y$ - " Break lines at word boundaries if possible - set linebreak +" ZW does an unconditional write for this buffer +nnoremap ZW :write! +" ZA does an unconditional write for all buffers +nnoremap ZA :wall! - " Precede continued lines with '...' - set showbreak=... +" Use different keys for global and local leaders +if 1 + let g:mapleader = '\' + let g:maplocalleader = '_' +endif - " If we have the option, indent wrapped lines as much as the first line - if exists('+breakindent') - set breakindent - endif +" \a toggles 'formatoptions' 'a' flag using a plugin +nnoremap a :ToggleOptionFlagLocal formatoptions a +" \b toggles copy-pasteable linebreak settings +nmap b CopyLinebreakToggle +" Current date and time insertion commands, requiring POSIX date(1) +if has('unix') + " \d: Local date + nnoremap d :read !date + " \D: UTC + nnoremap D :read !date -u +endif +" \f shows the current 'formatoptions' at a glance +nnoremap f :set formatoptions? +" \h toggles highlighting search results +nnoremap h :set hlsearch! hlsearch? +" \i toggles showing matches as I enter my pattern +nnoremap i :set incsearch! incsearch? +" \l toggles showing tab, end-of-line, and trailing whitespace +nnoremap l :set list! list? +" \n toggles line numbers +nnoremap n :set number! number? +" \p toggles paste mode +set pastetoggle=p +" \s toggles spell checking +nnoremap s :setlocal spell! spell? +" \t shows current filetype +nnoremap t :set filetype? +" \u sets US English spelling +nnoremap u :setlocal spelllang=en_us spelllang? +" \w toggles wrapping +nnoremap w :set wrap! wrap? +" \x strips trailing whitespace via a custom plugin +nmap x StripTrailingWhitespace +" \z sets NZ English spelling +nnoremap z :setlocal spelllang=en_nz spelllang? +" Add the packaged version of matchit.vim included in the distribution, if +" possible; plugin/macros.vim loads this for older Vims +if has('packages') + packadd! matchit +endif + +" A few very important custom digraphs +if has('digraphs') + digraph ./ 8230 " Ellipsis (HORIZONTAL ELLIPSIS U+2026) + digraph %% 8984 " Mac command key (PLACE OF INTEREST SIGN U+2318) + digraph 8: 9731 " Snowman (SNOWMAN U+2603) endif " Disable most core plugin stuff that I don't use; after/plugin/dist.vim @@ -331,28 +337,6 @@ if 1 endif -" Insert blank lines above and below via my custom unimpaired.vim rip -nmap [ PutBlankLinesAbove -nmap ] PutBlankLinesBelow - -" \b toggles copy-pasteable linebreak settings -nmap b CopyLinebreakToggle - -" \x strips trailing whitespace via a custom plugin -nmap x StripTrailingWhitespace - -" \a toggles 'f' flag in 'formatoptions' to reformat paragraphs to 'textwidth' -" on all insert or delete operations -if has('user_commands') - nnoremap a :ToggleOptionFlagLocal formatoptions a -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') - packadd! matchit -endif - " Source all .vim files from ~/.vim/config, which may override any of the " above runtime! config/*.vim -- cgit v1.2.3