diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-05-30 23:15:52 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-05-30 23:15:52 +1200 |
commit | 9e17f60eec422d2fd2669b909d602dfb05ac5468 (patch) | |
tree | 8d810790f13860348940145477d7de535c440d36 | |
download | vim-fixed-join-9e17f60eec422d2fd2669b909d602dfb05ac5468.tar.gz vim-fixed-join-9e17f60eec422d2fd2669b909d602dfb05ac5468.zip |
First commitv0.1.0
Copied with minimal changes from tejr's dotfiles suite, v0.35.0.
-rw-r--r-- | README.markdown | 13 | ||||
-rw-r--r-- | doc/fixed_join.txt | 45 | ||||
-rw-r--r-- | plugin/fixed_join.vim | 45 |
3 files changed, 103 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..a707ef1 --- /dev/null +++ b/README.markdown @@ -0,0 +1,13 @@ +fixed\_join.vim +=============== + +This plugin provides a mapping target and an optional command to `:join` lines +in normal mode while keeping the cursor in-place. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ diff --git a/doc/fixed_join.txt b/doc/fixed_join.txt new file mode 100644 index 0000000..c1fc4dc --- /dev/null +++ b/doc/fixed_join.txt @@ -0,0 +1,45 @@ +*fixed_join.txt* For Vim version 7.0 Last change: 2018 May 30 + +DESCRIPTION *fixed_join* + +This plugin provides a mapping target and an optional command to `:join` lines +in normal mode while keeping the cursor in-place. + +REQUIREMENTS *fixed_join-requirements* + +This plugin is only available if 'compatible' is not set. + +MAPPINGS *fixed_join-mappings* + *<Plug>FixedJoin* + +This plugin provides a mapping target |<Plug>FixedJoin| to create a binding +for a user to `:join` lines in normal mode without the cursor jumping around. + +If the user's configuration does not specify a mapping to this target by the +time this plugin is loaded, it will attempt to map 'J' in normal mode to +simply replace the default functionality. + +COMMANDS *fixed_join-commands* + *:FixedJoin* + +The plugin also provides a `:FixedJoin` command if Vim has the +|+user_commands| feature, but this is not required. + +ALTERNATIVE *fixed-join-alternative* + +If you don't mind clobbering a mark, this whole plugin can be replaced with +one mapping in your |vimrc|: +> + :nnoremap J mzJ`z +< +This was what the author was doing before writing this plugin as an exercise. + +AUTHOR *fixed_join-author* + +Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. + +LICENSE *fixed_join-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/fixed_join.vim b/plugin/fixed_join.vim new file mode 100644 index 0000000..2e7f2ab --- /dev/null +++ b/plugin/fixed_join.vim @@ -0,0 +1,45 @@ +" +" fixed_join.vim: User-defined key mapping and optional command to keep cursor +" in place when joining lines in normal mode. +" +" Author: Tom Ryder <tom@sanctum.geek.nz> +" License: Same as Vim itself +" +if exists('g:loaded_fixed_join') || &compatible + finish +endif +let g:loaded_fixed_join = 1 + +" 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 +noremap <silent> <unique> + \ <Plug>FixedJoin + \ :<C-U>call <SID>FixedJoin()<CR> + +" If there's no mapping to it already, try to bind normal-mode J to it, to +" simply replace the old functionality +nmap <unique> + \ J + \ <Plug>FixedJoin + +" Create a command as well in case it's useful +if has('user_commands') + command -nargs=0 + \ FixedJoin + \ call <SID>FixedJoin() +endif |