jalvesaq / Nvim-R

Vim plugin to work with R
GNU General Public License v2.0
966 stars 125 forks source link

<Plug> mappings don't work if made after vim loads (Esp RSendMotion) #470

Closed BlueDrink9 closed 4 years ago

BlueDrink9 commented 4 years ago

I've reproduced minimally in terms of vimrc.

:nmap q <Plug>RClearConsole, then pressing q doesn't seem to do anything. No errors, either, so the plug mapping exists. This works in minimal repro.

RSendMotion doesn't work, even in minimal repro. \m does.

nmap <LocalLeader>vd <Plug>RViewDF is the same.

The mapping clearly exists:

:map q

n q <Plug>RSendMotion

When I set verbose=99 and do qw on a letter, nothing is output.

Manually mapping it to what \m is set to works.

BlueDrink9 commented 4 years ago

I think the issue is in mapping them after nvim-R starts. When mapping them in the vimrc before or after calling Plug#end() (using vim-plug to manage plugins), the plug mappings do work. Mapping them in a function called after nvim-R loads, however, does not work.

The output of map q is identical for working and not working mappings.

BlueDrink9 commented 4 years ago

Actually, calling the function once vim loads, but before starting nvim-R, also doesn't work. Calling the function in the vimrc does work. Calling the function from au VimEnter * does not work.

Calling from autocmd sourcepre and sourcepost does work, with both * and r.vim

Calling on bufread and bufreadpost works. bufenter does not. UIEnter does not. winenter does not.

Calling as a -c arg doesn't work.

By 'not working' I mean the mapping is created, but does nothing.

jalvesaq commented 4 years ago

The documentation (section Custom key bindings) says:

After changing the maps in your vimrc, you have to restart Vim.

But actually there a minor bug in RViewDF and I'm going to fix it now.

BlueDrink9 commented 4 years ago

But I'm not changing them in my vimrc, I'm setting them in vim! Otherwise it's impossible to set maps for just R buffers

jalvesaq commented 4 years ago

All maps are created with the <buffer> argument.

Note: I'm very busy and have almost no spare time to maintain my projects on Github. When someone opens an issue about something that is working for many years, my first guess is that there is no bug at all and that the person has some configuration problem. So, instead of trying to fix a problem that I think doesn't exist, I simply wait until the user reports what he or she has managed to fix its configuration files. Maybe the problem is caused by another plugin. Did you try to disable all other plugins?

I can't understand your issue. I know that you are trying to change mappings, but the maps are customizable since about 2013. So, could you, please, better explain the context of your problem?

BlueDrink9 commented 4 years ago

Ok, that's understandable. If nothing has changed, I'll check my config more thoroughly, although I don't know where else to look. But yes, as mentioned, I have done a minimal reproduction.

Yes. Maps created with the <buffer> arg only act for the buffer they are created in. Therefore creating them in vimrc normally will only create them for the first buffer loaded. In my case, after loading an R file, I do :nmap <buffer> q <Plug>RClearConsole, then pressing q does nothing. The same happens with other nvim-R mappings. This also happens from a minimal vimrc with just vim-plug and nvim-R. If I put the mapping in my vimrc, it works but cannot be buffer-local.

When you say "maps are customizable", does nvim-R have a custom way to set up maps just for R files? Or is an autocmd the recommended way?

I hope this helps you understand my question. I appreciate your time

jalvesaq commented 4 years ago

It's not a good idea to start mappings in Normal mode with regular letters because they all are already mapped to something. This is the reason why all Nvim-R's key bindings start with <LocalLeader>. For example, q is the first of two keys to start recording what will be typed next. Please, see:

:h recording

You should not use the argument <buffer> when defining what sequence of keys should trigger a function:

 nmap q <Plug>RClearConsole

You can customize Nvim-R's key bindings only in the vimrc.

BlueDrink9 commented 4 years ago

So to clarify, you don't support users remapping nvim-R's <Plug> commands in a buffer-local fashion, without using <localleader>? I assume that is a limitation of the CreateMapping function you use?

If this is the case, I think it would be good to create a feature-request issue for it. This wouldn't be for you to fix, but for future maintainers to consider.

Other repos allow more specific customisation, without requiring the use of localleader. For example, if I have a neoterm 'send line to repl' mapping on <leader>ss, the current system with nvim-R prevents me from overriding that with a mapping for R buffers only. Does that use-case make sense?

It's not a good idea to start mappings [...]

That's the purpose of customization, wouldn't you agree? Let the user make this choice. In this case, I don't actually use q, but <c-p> (which I don't have use for as a default map.) q is what I was using for simplicity of debugging.

jalvesaq commented 4 years ago

I'm sorry, but I really don't have time for this issue. Please, feel free to open another issue and wait until someone can help you.