From 937458202c8311ecbed7a51a4cec1d1941a6bfd0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 12 Nov 2017 20:57:13 +1300 Subject: Bind norm J on fixed_join.vim load if appropriate If there are no mappings to the FixedJoin target that the fixed_join.vim plugin provides at the time it is loaded, and the line-joining function of normal-mode J is not already mapped, the plugin will try to map it itself, for a more plug-and-play. --- vim/config/whitespace.vim | 7 ------- vim/doc/fixed_join.txt | 9 ++++++--- vim/plugin/fixed_join.vim | 6 ++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim index 12d41a4e..981def81 100644 --- a/vim/config/whitespace.vim +++ b/vim/config/whitespace.vim @@ -24,12 +24,5 @@ set shiftround " despite the noble Steve Losh's exhortations set nojoinspaces -" 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') - nmap J FixedJoin -endif - " \x strips trailing whitespace via a custom plugin nmap x StripTrailingWhitespace diff --git a/vim/doc/fixed_join.txt b/vim/doc/fixed_join.txt index df0df251..834a3569 100644 --- a/vim/doc/fixed_join.txt +++ b/vim/doc/fixed_join.txt @@ -4,10 +4,13 @@ Author: Tom Ryder License: Same terms as Vim itself (see |license|) This plugin provides a mapping target FixedJoin to create a binding for a -user to join lines in normal mode without the cursor jumping around. +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. -If also provides a :FixedJoin command if you have +user_commands, but this is -not required. +The plugin also provides a :FixedJoin command if you have +user_commands, but +this is not required. This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun off into a separate distribution as it solidifies and this documentation diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim index 83977c2f..2e7f2abd 100644 --- a/vim/plugin/fixed_join.vim +++ b/vim/plugin/fixed_join.vim @@ -31,6 +31,12 @@ noremap \ FixedJoin \ :call FixedJoin() +" If there's no mapping to it already, try to bind normal-mode J to it, to +" simply replace the old functionality +nmap + \ J + \ FixedJoin + " Create a command as well in case it's useful if has('user_commands') command -nargs=0 -- cgit v1.2.3