diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-04 02:27:42 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-04 02:28:16 +1300 |
commit | b0a15bf0e7aae09b8a875a3803632e878be595bd (patch) | |
tree | 5088d5c15fba8ed4812344972e7ecf32e764fee8 | |
parent | Use <Plug> prefix, make space strip configurable (diff) | |
download | dotfiles-b0a15bf0e7aae09b8a875a3803632e878be595bd.tar.gz dotfiles-b0a15bf0e7aae09b8a875a3803632e878be595bd.zip |
Spin stable join config out into new plugin
Again using the <Plug> mapping abstraction and not defining the mapping
for the user.
-rw-r--r-- | vim/config/join.vim | 25 | ||||
-rw-r--r-- | vim/plugin/fixed_join.vim | 26 |
2 files changed, 30 insertions, 21 deletions
diff --git a/vim/config/join.vim b/vim/config/join.vim index 7d764dce..ebf42a8b 100644 --- a/vim/config/join.vim +++ b/vim/config/join.vim @@ -2,26 +2,9 @@ " despite the noble Steve Losh's exhortations set nojoinspaces -" Keep my cursor in place when I join lines +" Rebind normal J to run plugin-defined join that doesn't jump around, but +" only if we have the eval feature, because otherwise this mapping won't exist +" and we should keep the default behaviour if has('eval') - - " Declare function - function! s:StableNormalJoin() - - " Save current cursor position - let l:lc = line('.') - let l:cc = col('.') - - " Build and execute join command - let l:command = '.,+' . v:count1 . 'join' - execute l:command - - " Restore cursor position - call cursor(l:lc, l:cc) - - endfunction - - " Remap J to the above function - nnoremap <silent> J :<C-U>call <SID>StableNormalJoin()<CR> - + nmap J <Plug>FixedJoin endif diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim new file mode 100644 index 00000000..ef1b03ef --- /dev/null +++ b/vim/plugin/fixed_join.vim @@ -0,0 +1,26 @@ +" User-defined key mapping to keep cursor in place when joining lines in +" normal mode +" Suggesting mapping: normal J +if has('eval') + + " Declare function + function! s:FixedJoin() + + " Save current cursor position + let l:lc = line('.') + let l:cc = col('.') + + " Build and execute join command + let l:command = '.,+' . v:count1 . 'join' + execute l:command + + " Restore cursor position + call cursor(l:lc, l:cc) + + endfunction + + " Create mapping proxy to the function just defined + " Suggesting mapping: normal J + noremap <Plug>FixedJoin + \ :<C-U>call <SID>FixedJoin()<CR> +endif |