From b0a15bf0e7aae09b8a875a3803632e878be595bd Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 02:27:42 +1300 Subject: Spin stable join config out into new plugin Again using the mapping abstraction and not defining the mapping for the user. --- vim/plugin/fixed_join.vim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 vim/plugin/fixed_join.vim (limited to 'vim/plugin') 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 FixedJoin + \ :call FixedJoin() +endif -- cgit v1.2.3