michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
555 stars 72 forks source link

Fix mappings to <Plug> in ViM #131

Closed leamsi closed 1 year ago

leamsi commented 1 year ago

At least in ViM (I'm still stuck on 8.2 here) it seems you cannot create a mapping from a key to a with "noremap", they need to be the regular version.

michal-h21 commented 1 year ago

That's strange, we had to change from regular mappings to noremap, thanks to this PR, which fixed issue #85. I already have vim 9.0, but I think it should work in older Vim versions. Isn't it possible that there is another issue?

leamsi commented 1 year ago

This is a well know issue with noremap and <Plug>. See for example the explanation in this reddit thread from four years ago: https://www.reddit.com/r/vim/comments/78izt4/please_help_understand_how_to_use_plug_mapping/doufox8/ or the accepted answer in this stack exchange post: https://vi.stackexchange.com/questions/31012/what-does-plug-do-in-vim . It could be they fixed this in Vim9 though.

Honestly, it seems to me that #85 should've been closed as working as intended... A lot of things are going to break if you map <Esc> to <Nop> like that user did, I'm actually pretty sure a lot of other plugins with insert mode mappings use <Esc> in their mappings

A possible solution so that user can keep their <Esc> mapping is to use recursive map with <C-O><Plug>ZettelSearchMap ... and pray that this user hasn't mapped <C-O> to anything :P. This will change the behavior a little bit as the user will be back in insert mode after the function returns (and I actually prefer that). I just tried that locally and it works, even with <Esc> mapped to <Nop>. What do you think?

michal-h21 commented 1 year ago

Thanks for the links, it seems that you are right, and I accepted this PR.