tpope / vim-rsi

rsi.vim: Readline style insertion
http://www.vim.org/scripts/script.php?script_id=4359
590 stars 36 forks source link

Allow disabling mappings in insert or cmdline mode #48

Closed hupfdule closed 5 years ago

hupfdule commented 5 years ago

Introduces the following new options:

The diff of this PR is way larger than I would like it to be (as it basically just wraps a few lines with a check for the above mentioned settings). But the alternative would have been to wrap nearly each line separately, which in my opinion would be even worse.

This PR fixes #39 and #41. It is very similar to #26, but extends to all mappings, not only the Meta mappings.

With this patch I am able to use vim-rsi for insert-mode and readline.vim for command line mode.

tpope commented 5 years ago

RSI's maps are by their very nature non-essential, so I think it would make sense if it always deferred to other maps. I'd accept something like the following:

function! s:Map(mode, flags, lhs, rhs) abort
  if empty(mapcheck(a:lhs, a:mode))
    exe a:mode . 'map <expr>' a:flags a:lhs a:rhs
  endif
endfunction
hupfdule commented 5 years ago

While your suggestion would avoid overwriting existing mappings, I don't think it would fully resolve that problem of conflicting with readline.vim. That would only be possible if vim-rsi is loaded after readline.vim. Some plugin managers support such a thing, others don't. And when not using any plugin manager this is even harder to achieve.

Also it would not help if someone wanted to have readline-style keybindings only in command mode (like readline.vim does) or (less likely) the other way around.

Therefore I don't think I will make another PR with your suggestion. I can live with having my own fork of it.

Thank you for having a look into it!

hupfdule commented 5 years ago

As @justinmk explicitly "dislikes" this PR I am a bit curious about what he dislikes about it…

tpope commented 5 years ago

It will work regardless of load order assuming readline.vim doesn't also implement this behavior.

hupfdule commented 5 years ago

Ah, I see. If vim-rsi is loaded first, it will map these key and those will be overwritten later by readline.vim. If readline.vim is loaded first, it will not overwrite these mappings.

Still, this doesn't allow for a user to activate vim-rsi only in insert mode or only in commandline mode.

Nevertheless, I would be glad if you introduce this conditional mapping, but I think it is better if you do it yourself, since you know best how it fits into vim-rsi.