diff options
Diffstat (limited to 'vim')
-rw-r--r-- | vim/after/ftplugin/mail.vim | 67 | ||||
-rw-r--r-- | vim/after/indent/gitconfig.vim | 6 | ||||
-rw-r--r-- | vim/autoload/paste_insert.vim | 14 | ||||
m--------- | vim/bundle/paste_open | 0 | ||||
-rw-r--r-- | vim/filetype.vim | 6 | ||||
-rw-r--r-- | vim/ftplugin/csv.vim | 6 | ||||
-rw-r--r-- | vim/ftplugin/password.vim | 9 | ||||
-rw-r--r-- | vim/ftplugin/tsv.vim | 13 | ||||
-rw-r--r-- | vim/indent/csv.vim | 8 | ||||
-rw-r--r-- | vim/indent/html.vim | 3 | ||||
-rw-r--r-- | vim/indent/password.vim | 11 | ||||
-rw-r--r-- | vim/indent/tsv.vim | 13 | ||||
-rw-r--r-- | vim/plugin/paste_insert.vim | 6 | ||||
-rw-r--r-- | vim/plugin/spellfile_local.vim | 2 | ||||
-rw-r--r-- | vim/vimrc | 106 |
15 files changed, 145 insertions, 125 deletions
diff --git a/vim/after/ftplugin/mail.vim b/vim/after/ftplugin/mail.vim index cfb738a1..f4a4c91d 100644 --- a/vim/after/ftplugin/mail.vim +++ b/vim/after/ftplugin/mail.vim @@ -1,10 +1,17 @@ " Don't append spaces after quote chars, for strict compliance with " format=flowed let b:quote_space = 0 +let b:undo_ftplugin .= '|unlet b:quote_space' " If something hasn't already moved the cursor, we'll move to an optimal point " to start writing -if line('.') == 1 && col('.') == 1 +function! s:SuggestStart() abort + + " Move to top of buffer + call setpos('.', [0, 1, 1, 0]) + + " Move to body text + call search('\m^$', 'c') | + " Start by trying to move to the first quoted line; this may fail if there's " no quote, which is fine @@ -35,29 +42,45 @@ if line('.') == 1 && col('.') == 1 " Now move to the first quoted or unquoted blank line call search('\m^>\= *$', 'c') - -endif +endfunction +command! -bar -buffer SuggestStart + \ call s:SuggestStart() +let b:undo_ftplugin .= '|delcommand SuggestStart' +SuggestStart " Normalise quoting -for lnum in range(1, line('$')) - - " Get current line - let line = getline(lnum) - - " Get the leading quote string, if any; stop if there isn't one - let quote = matchstr(line, '^[> ]\+') - if strlen(quote) == 0 - continue - endif - - " Normalise the quote with no spaces - let quote = substitute(quote, '[^>]', '', 'g') - - " Re-set the line - let line = substitute(line, '^[> ]\+', quote, '') - call setline(lnum, line) - -endfor +function! s:StrictQuote() abort + let body = 0 + for lnum in range(1, line('$')) + + " Get current line + let line = getline(lnum) + + " Skip lines until we hit a blank line, meaning body text + let body = body || !strlen(line) + if !body + continue + endif + + " Get the leading quote string, if any; skip if there isn't one + let quote = matchstr(line, '^>[> ]*') + if !strlen(quote) + continue + endif + + " Normalise the quote with no spaces + let quote = substitute(quote, '[^>]', '', 'g') + + " Re-set the line + let line = substitute(line, '^[> ]\+', quote, '') + call setline(lnum, line) + + endfor +endfunction +command -bar -buffer StrictQuote + \ call s:StrictQuote() +let b:undo_ftplugin .= '|delcommand StrictQuote' +StrictQuote " Add a space to the end of wrapped lines for format-flowed mail setlocal formatoptions+=w diff --git a/vim/after/indent/gitconfig.vim b/vim/after/indent/gitconfig.vim new file mode 100644 index 00000000..16a948ab --- /dev/null +++ b/vim/after/indent/gitconfig.vim @@ -0,0 +1,6 @@ +" Use tabs for indent in Git config files, rather than fighting with the +" frontend tool +setlocal noexpandtab +setlocal softtabstop=0 +let &shiftwidth = &tabstop +let b:undo_indent .= '|setlocal expandtab< softtabstop< shiftwidth<' diff --git a/vim/autoload/paste_insert.vim b/vim/autoload/paste_insert.vim new file mode 100644 index 00000000..fe7cb35f --- /dev/null +++ b/vim/autoload/paste_insert.vim @@ -0,0 +1,14 @@ +augroup paste_insert + autocmd! +augroup END + +function! paste_insert#() abort + autocmd! paste_insert + autocmd paste_insert CursorHold,CursorMoved,User <buffer> + \ set nopaste paste? + \|autocmd! paste_insert + autocmd paste_insert InsertEnter <buffer> + \ set paste paste? + \|autocmd paste_insert InsertLeave <buffer> + \ doautocmd paste_insert User +endfunction diff --git a/vim/bundle/paste_open b/vim/bundle/paste_open deleted file mode 160000 -Subproject 79ee83eac32dbadf722df687e65f07d75a2f8ea diff --git a/vim/filetype.vim b/vim/filetype.vim index 848637dd..6b52fab9 100644 --- a/vim/filetype.vim +++ b/vim/filetype.vim @@ -239,12 +239,6 @@ augroup filetypedetect \,/etc/shadow- \,/etc/shadow.edit \ setfiletype passwd - " pass(1) password files - autocmd BufNewFile,BufRead - \ /dev/shm/pass.?*/?*.txt - \,$TMPDIR/pass.?*/?*.txt - \,/tmp/pass.?*/?*.txt - \ setfiletype password " Perl 5 files autocmd BufNewFile,BufRead \ ?*.pl diff --git a/vim/ftplugin/csv.vim b/vim/ftplugin/csv.vim index 162da402..9bd3e86e 100644 --- a/vim/ftplugin/csv.vim +++ b/vim/ftplugin/csv.vim @@ -4,8 +4,6 @@ if exists('b:did_ftplugin') endif let b:did_ftplugin = 1 -" No autoformatting, literal tabs -setlocal noautoindent -setlocal noexpandtab +" No autoformatting setlocal formatoptions= -let b:undo_ftplugin = 'setlocal autoindent< expandtab< formatoptions<' +let b:undo_ftplugin = 'formatoptions<' diff --git a/vim/ftplugin/password.vim b/vim/ftplugin/password.vim deleted file mode 100644 index 28f5a5e9..00000000 --- a/vim/ftplugin/password.vim +++ /dev/null @@ -1,9 +0,0 @@ -" Only do this when not yet done for this buffer -if exists('b:did_ftplugin') - finish -endif -let b:did_ftplugin = 1 - -" No autoformatting -setlocal formatoptions= -let b:undo_ftplugin = 'setlocal formatoptions<' diff --git a/vim/ftplugin/tsv.vim b/vim/ftplugin/tsv.vim index 162da402..f78da35f 100644 --- a/vim/ftplugin/tsv.vim +++ b/vim/ftplugin/tsv.vim @@ -1,11 +1,2 @@ -" Only do this when not yet done for this buffer -if exists('b:did_ftplugin') - finish -endif -let b:did_ftplugin = 1 - -" No autoformatting, literal tabs -setlocal noautoindent -setlocal noexpandtab -setlocal formatoptions= -let b:undo_ftplugin = 'setlocal autoindent< expandtab< formatoptions<' +" TSVs have the same filetype options as CSVs +runtime! ftplugin/csv.vim diff --git a/vim/indent/csv.vim b/vim/indent/csv.vim index fd3c99de..78bddd33 100644 --- a/vim/indent/csv.vim +++ b/vim/indent/csv.vim @@ -4,8 +4,12 @@ if exists('b:did_indent') endif let b:did_indent = 1 -" Manual indenting and literal tabs for CSVs +" Manual indenting setlocal noautoindent +let b:undo_indent = 'setlocal autoindent<' + +" Literal tabs setlocal noexpandtab setlocal softtabstop=0 -let b:undo_indent = 'setlocal autoindent< expandtab< softtabstop<' +let &shiftwidth = &tabstop +let b:undo_indent = 'setlocal expandtab< softtabstop< shiftwidth<' diff --git a/vim/indent/html.vim b/vim/indent/html.vim index d93443a7..b31564f6 100644 --- a/vim/indent/html.vim +++ b/vim/indent/html.vim @@ -1,2 +1,5 @@ +" No load guard--we want this to run just before the stock runtime script to +" change its behaviour. We don't want to block it. + " Indent after <p> paragraph tags too let html_indent_inctags = 'p' diff --git a/vim/indent/password.vim b/vim/indent/password.vim deleted file mode 100644 index e37d0387..00000000 --- a/vim/indent/password.vim +++ /dev/null @@ -1,11 +0,0 @@ -" Only do this when not done yet for this buffer -if exists('b:did_indent') - finish -endif -let b:did_indent = 1 - -" Manual indenting and literal tabs for passwords -setlocal noautoindent -setlocal noexpandtab -setlocal softtabstop=0 -let b:undo_indent = 'setlocal autoindent< expandtab< softtabstop<' diff --git a/vim/indent/tsv.vim b/vim/indent/tsv.vim index adbde97d..ae72397c 100644 --- a/vim/indent/tsv.vim +++ b/vim/indent/tsv.vim @@ -1,11 +1,2 @@ -" Only do this when not done yet for this buffer -if exists('b:did_indent') - finish -endif -let b:did_indent = 1 - -" Manual indenting and literal tabs for TSVs -setlocal noautoindent -setlocal noexpandtab -setlocal softtabstop=0 -let b:undo_indent = 'setlocal autoindent< expandtab< softtabstop<' +" TSVs have the same indent options as CSVs +runtime! indent/csv.vim diff --git a/vim/plugin/paste_insert.vim b/vim/plugin/paste_insert.vim new file mode 100644 index 00000000..be578746 --- /dev/null +++ b/vim/plugin/paste_insert.vim @@ -0,0 +1,6 @@ +if exists('loaded_paste_insert') + finish +endif +let loaded_paste_insert = 1 +command! -bar PasteInsert + \ call paste_insert#() diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index b04b7573..c026d626 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -10,7 +10,7 @@ let s:spellfile = join([ Establish $MYVIM/cache/spell execute 'set spellfile=$MYVIM/cache/spell/'.s:spellfile -command! AddLocalSpellFile +command! -bar AddLocalSpellFile \ call spellfile_local#() augroup spellfile_local @@ -204,33 +204,33 @@ endfunction command! -bar ReloadVimrc \ noautocmd source $MYVIMRC | call s:ReloadVimrc() -" We'll now reset and define a group of automatic command hooks specific to -" matters related to reloading the vimrc itself. +" We'll now create or reset a group of automatic command hooks specific to +" matters related to reloading the vimrc itself, or maintaining and managing +" options set within it. " augroup vimrc autocmd! +augroup END - " Reload the stub vimrc, and thereby this main one, each time either of them - " is saved. This often makes errors in the file immediately apparent, and - " saves restarting Vim or running the :source command manually, which - " I almost always want to do after changing my vimrc file anyway. - " - autocmd BufWritePost $MYVIMRC,$MYVIM/vimrc - \ ReloadVimrc - - " If Vim is new enough (v7.0.187) to support the ##SourceCmd event for - " automatic command hooks, we'll also apply a hook for that event to catch - " invocations of :source of either vimrc file, and translate that into - " reloading the stub vimrc. - " - " <https://github.com/vim/vim/releases/tag/v7.0.187> - " - if exists('##SourceCmd') - autocmd SourceCmd $MYVIMRC,$MYVIM/vimrc - \ ReloadVimrc - endif +" Reload the stub vimrc, and thereby this main one, each time either of them +" is saved. This often makes errors in the file immediately apparent, and +" saves restarting Vim or running the :source command manually, which +" I almost always want to do after changing my vimrc file anyway. +" +autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc + \ ReloadVimrc -augroup END +" If Vim is new enough (v7.0.187) to support the ##SourceCmd event for +" automatic command hooks, we'll also apply a hook for that event to catch +" invocations of :source of either vimrc file, and translate that into +" reloading the stub vimrc. +" +" <https://github.com/vim/vim/releases/tag/v7.0.187> +" +if exists('##SourceCmd') + autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc + \ ReloadVimrc +endif " We're going to be creating a few directories now. The code to do so in " a compatible way is verbose, mostly because we need to check whether the @@ -962,29 +962,32 @@ if !exists('syntax_on') syntax enable endif -" We'll have Vim try to use my 'sahara' fork of the 'desert256' color scheme, -" and if it manages to do so without errors, turn on the 'cursorline' feature, -" since the scheme configures it and 'cursorcolumn' to be a very dark gray -" that doesn't stand out too much against a black background. Aside from the -" aforementioned experiment with monochrome terminals, I exclusively use dark -" backgrounds. +" Before we attempt to pick a syntax highlighting color scheme, we'll set up +" a couple of hooks for colorscheme loading. In this case, we turn +" 'cursorline' on if my 'sahara' colorscheme is loaded, since I've configured +" it to be a very dark gray that doesn't stand out too much against a black +" background. For any other colorscheme, turn the option off, because it +" almost always stands out too much for my liking. " +autocmd vimrc ColorScheme * + \ set nocursorline +autocmd vimrc ColorScheme sahara + \ set cursorline + +" We'll have Vim try to use my 'sahara' fork of the 'desert256' color scheme. " If we fail to load the color scheme, for whatever reason, suppress the -" error, and reset the syntax highlighting, 'background', and 'cursorline' for -" dark-background default colors. I used it for years; it looks and works -" just fine. +" error, and ensure a dark background for the default colorscheme. " -" There's also a very simple grayscale color scheme I occasionally use -" instead called 'juvenile', which is included as a Git submodule with this -" dotfiles distribution. +" There's also a very simple grayscale color scheme I occasionally use instead +" called 'juvenile', which is included as a Git submodule with this dotfiles +" distribution. " try colorscheme sahara - set cursorline catch - colorscheme default - set background=dark - set nocursorline + if &background !=# 'dark' + set background=dark + endif endtry " My mapping definitions begin here. I have some general personal rules for @@ -1251,10 +1254,6 @@ xmap <Leader>n <Esc><Leader>ngv nnoremap <Leader>N \ :<C-U>set ruler! ruler?<CR> xmap <Leader>N <Esc><Leader>Ngv -"" Leader,p toggles paste mode -nnoremap <Leader>p - \ :<C-U>set paste! paste?<CR> -xmap <Leader>p <Esc><Leader>pgv "" Leader,w toggles soft wrapping nnoremap <Leader>w \ :<C-U>setlocal wrap! wrap?<CR> @@ -1314,6 +1313,15 @@ nnoremap <Leader>L \ :<C-U>ToggleFlagLocal colorcolumn +1<CR> xmap <Leader>L <Esc><Leader>Lgv +" This mapping uses my paste_insert.vim plugin to queue up automatic commands +" for the next insert operation. It's still pretty new. It replaces my old +" paste_open.vim plugin which did this only for opening new lines, and which +" kept confusing me. I'm hoping this will be better. + +"" Leader,p prepares the next insert for paste mode +nnoremap <Leader>p + \ :<C-U>PasteInsert<CR> + " These mappings are for managing filetypes. The first one uses the " :ReloadFileType command that was defined much earlier in this file for " application in the vimrc reload command. @@ -1361,6 +1369,9 @@ nnoremap <Leader>H "" Leader,k shows my marks nnoremap <Leader>k \ :<C-U>marks<CR> +"" Leader,K shows functions +nnoremap <Leader>K + \ :<C-U>function<CR> "" Leader,m shows normal maps nnoremap <Leader>m \ :<C-U>nmap<CR> @@ -1370,6 +1381,9 @@ nnoremap <Leader>M "" Leader,S shows loaded scripts nnoremap <Leader>S \ :<C-U>scriptnames<CR> +"" Leader,U shows user commands +nnoremap <Leader>U + \ :<C-U>command<CR> "" Leader,v shows all global and internal variables nnoremap <Leader>v \ :<C-U>let g: v:<CR> @@ -1381,8 +1395,8 @@ nnoremap <Leader>y \ :<C-U>registers<CR> " This group contains mappings concerned with buffer navigation and -" management. I use the "jetpack" buffer jumper one like crazy; I really like -" it. I got it from one of bairui's "Vim and Vigor" comics: +" management. I use the "jetpack" buffer jumper one a lot. I got it from one +" of bairui's "Vim and Vigor" comics: " " <http://of-vim-and-vigor.blogspot.com/p/vim-vigor-comic.html> @@ -1485,10 +1499,6 @@ nnoremap <Leader>? "" Leader,. runs the configured make program into the location list nnoremap <Leader>. \ :<C-U>lmake!<CR> -"" Leader,o opens a line below in paste mode -nmap <Leader>o <Plug>(PasteOpenBelow) -"" Leader,O opens a line above in paste mode -nmap <Leader>O <Plug>(PasteOpenAbove) "" Leader,q formats the current paragraph nnoremap <Leader>q gqap "" Leader,r acts as a replacement operator |