Do you use <unique> in your plugin mappings?

19 views
Skip to first unread message

Lifepillar

unread,
Sep 26, 2017, 3:07:44 AM9/26/17
to vim...@googlegroups.com
I have a question for you plugin developers (but I am interested also in
a user's perspective). What do you think is the best approach to deal
with a conflicting mapping (i.e., a mapping already defined elsewhere)
in a plugin?

I currently define my plugin's mappings with <unique>, but from time to
time users report `E227: mapping already exists` errors as bugs, so I am
not sure that this is the best approach.

Btw, "do not define any mapping in a plugin" is not an answer. My
plugins already have such an option, but for some plugins providing
mappings by default is the natural choice.

Lifep.

Luc Hermitte

unread,
Sep 26, 2017, 3:55:13 AM9/26/17
to vim use
Hi,

> I have a question for you plugin developers (but I am interested also
> in a user's perspective). What do you think is the best approach to
> deal with a conflicting mapping (i.e., a mapping already defined
> elsewhere) in a plugin?
>
> I currently define my plugin's mappings with <unique>, but from time
> to time users report `E227: mapping already exists` errors as bugs,
> so I am not sure that this is the best approach.


I do use <unique> in my plugins. But only if the user doesn't override the default keybinding with his own. I rely on <plug>mappings to do so.

If the user report the error, well we need to explain her/him what can be done to silence the error. The user has to make a choice which we cannot do for her/him: either to continue with the keybinding defined in the .vimrc or provided in another plugin, or to choose another keybinding for our plugin.



In my ftplugins, I've used <unique> <plug>ged mappings a few times, but I'm not sure this is the best thing to do.
Which reminds me in a few places I've replaced <unique> with another approach that issues a less intrusive warning.

It's used with:
nnoremap <Plug>TogglePreviewIfHold :Toggle Cpreview_if_hold<cr>
call lh#mapping#plug({'lhs': '<localleader>tpw', 'rhs': '<Plug>TogglePreviewIfHold'}, 'n')

With lh#mapping#plug being defined over there: https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/mapping.vim#L99

HTH,

--
Luc Hermitte
Reply all
Reply to author
Forward
0 new messages