diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-09-12 23:47:40 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-09-12 23:47:40 +1200 |
commit | f06e6def650cf62af7a0bd7e067c578d2ba6fa8f (patch) | |
tree | ea5e6118f39e57d2f6958782ff50ce925a1479ee | |
parent | Merge branch 'hotfix/v1.68.1' (diff) | |
parent | Bump VERSION (diff) | |
download | dotfiles-f06e6def650cf62af7a0bd7e067c578d2ba6fa8f.tar.gz dotfiles-f06e6def650cf62af7a0bd7e067c578d2ba6fa8f.zip |
Merge branch 'release/v1.69.0'v1.69.0
* release/v1.69.0:
Bump VERSION
Replace paste_open.vim with paste_hook.vim
-rw-r--r-- | VERSION | 4 | ||||
-rw-r--r-- | vim/plugin/paste_hook.vim | 44 | ||||
-rw-r--r-- | vim/vimrc | 9 |
3 files changed, 52 insertions, 5 deletions
@@ -1,2 +1,2 @@ -tejr dotfiles v1.68.1 -Sun Sep 9 07:56:21 UTC 2018 +tejr dotfiles v1.69.0 +Wed Sep 12 11:47:40 UTC 2018 diff --git a/vim/plugin/paste_hook.vim b/vim/plugin/paste_hook.vim new file mode 100644 index 00000000..5697a198 --- /dev/null +++ b/vim/plugin/paste_hook.vim @@ -0,0 +1,44 @@ +" +" paste_hook.vim: Mapping target to add a self-clearing autocmd that unsets +" 'paste' on the next InsertLeave event, if set; intended for use as a prefix +" to an insert session to make it happen in paste mode. +" +" Author: Tom Ryder <tom@sanctum.geek.nz +" Copyright: Same as Vim itself +" +if exists('g:loaded_paste_hook') || &compatible + finish +endif +if !exists('##InsertLeave') + finish +endif +let g:loaded_paste_hook = 1 + +" Start paste mode, establish hook to end it +function! s:Set() abort + + " Do nothing if 'paste' is already set + if &paste + return + endif + + " Turn on 'paste' mode and set up the hook to clear it the next time we + " leave insert mode + set paste + augroup paste_hook + autocmd! + autocmd InsertLeave * call s:Clear() + augroup END + +endfunction + +" End paste mode and clear the hook that called us +function! s:Clear() abort + set nopaste + autocmd! paste_hook InsertLeave +endfunction + +" Set up mappings +nnoremap <silent> <unique> + \ <Plug>(PasteHook) + \ :<C-U>call <SID>Set()<CR> @@ -331,12 +331,15 @@ if exists(':xnoremap') endif " \o opens a line below in paste mode -nmap <Bslash>o <Plug>(PasteOpenBelow) +nmap <Bslash>o <Plug>(PasteHook)o " \O opens a line above in paste mode -nmap <Bslash>O <Plug>(PasteOpenAbove) +nmap <Bslash>O <Plug>(PasteHook)O -" \p toggles paste mode +" \p toggles paste mode, or sets a hook if plugin available nnoremap <Bslash>p :<C-U>set paste! paste?<CR> +if &loadplugins + nmap <Bslash>p <Plug>(PasteHook) +endif " \q formats the current paragraph nnoremap <Bslash>q gqap |