Nvim-R icon indicating copy to clipboard operation
Nvim-R copied to clipboard

R_assign = 0 is not behaving as expected; R_assign = 2 does behave as expected.

Open dewittpe opened this issue 2 years ago • 6 comments

I'm working in NeoVim 0.7.0 on a Mac.

:version                                                                                                                                                                                   
NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Monterey

with nvimcom_0.9-155 and the Nvim-R plugin from 45b9ea9.

With let R_assign = 0 in my init.vim file, which I've been using for several years, I expected the _ to not be replaced by the assignment operator <-. For reasons I cannot determine, as of this afternoon when I type an underscore it is replaced by the assignment operator.

When I replaced let R_assign = 0 with let R_assign = 2 in my init.vim file I get the behavior as defined in the documentation.

Other things I've tried and still had issues:

  • Reverting to Nvim-R to v0.9.16

  • Just for "fun" I tried this:

let R_assign = 1
let R_assign_map = "+"

and both _ and + were replaced by <-

Please let me know what additional details I can provided to help reproduce the behavior.

dewittpe avatar Apr 27 '22 22:04 dewittpe

I'm sorry, but I can't replicate the issue. Could you try a minimal init.vim? It looks like you or a plugin have somewhere set iabb <buffer> _ <-. Note that the current version of nvimcom is 0.9-131. Are you using the stable branch?

jalvesaq avatar Apr 28 '22 00:04 jalvesaq

I'll dig into this more. I am certain you are correct that there is a plugin or some other issue on my end causing this error. When starting to look at a minimal init.vim file I found that I would get the expected behavior, that is nothing happens, when I started nvim via

nvim -u NONE temp.R

but a _ would be replaced by <- if

nvim --noplugin temp.R

I'll post more details when I find them.

FWIW: the nvimcom version was the version that was installed after updating nvim and Nvim-R.

dewittpe avatar Apr 28 '22 01:04 dewittpe

I've tracked down a possible cause: syntax enable

I have removed all plug-ins from my bundle with the exception of pathogen and Nvim-R. Minimal init.vim that behaves as expected:

$ cat init1.vim
" Pathogen Plugin Manager
runtime bundle/vim-pathogen/autoload/pathogen.vim
execute pathogen#infect()

let R_assign = 0

and running nvim with this init file:

$ nvim -u init1.vim -c ":normal i_ #underscore retained" -c ":wq" eg1.R; cat eg1.R          
_ #underscore retained

Now, if I use init2.vim

$ cat init2.vim 
" Pathogen Plugin Manager
runtime bundle/vim-pathogen/autoload/pathogen.vim
execute pathogen#infect()

syntax enable
let R_assign = 0

the underscore is replaced with the assignment operator.

$ nvim -u init2.vim -c ":normal i_ #underscore replaced" -c ":wq" eg2.R; cat eg2.R
 <-  #underscore replaced

dewittpe avatar Apr 28 '22 14:04 dewittpe

Thanks for investigating this! I will look at the issue over the weekend.

jalvesaq avatar Apr 28 '22 22:04 jalvesaq

Using vim-plug, I can't replicate the issue with the development version of Neovim. I replaced my init.vim with this:

call plug#begin('~/.cache/vim-plug')
Plug 'jalvesaq/Nvim-R'
call plug#end()

let R_assign = 0

Adding syntax enable to the end of the init.vim makes no difference.

jalvesaq avatar Apr 30 '22 17:04 jalvesaq

I am having the same issue; setting R_assign = 2 works as expected, but R_assign = 3 or R_assign = 0 lead to underscore expansion regardless of the context in which the underscore is typed. The issue started for me after upgrading my OS (Archlinux), which updated neovim to 0.7.0-3, without updating Nvim-R. Updating Nvim-R did not change it. So it seems that the issue is related to the neovim update, at least on my system. I have not had a chance to try turning off all other plugins to see if that fixes the issue.

mikemc avatar May 02 '22 14:05 mikemc

I encountered this issue as well, I cloned the repo, hardcoded the default value to 0 in R/common_global.vim and had packer install it from the local copy and it seems to work now. So it seems like the problem for me was R_assign=0 wasn't sticking for some reason? I tried it in .vimrc, init.lua, after/Nvim-R.lua I'm building a new config from scratch so there's probably something I'm doing that's causing a problem. I'll investigate some more when I have time and report back what I learn, but for now it's working fine!

As a beginner R user I'm curious what the intended user experience is for this feature? ie. how do you use ggplot2 with this on? Is it assumed the user will create a keybinding to toggle this off to type something like geom_ is there another keybinding to type an underscore?

Thanks for the great plugin!

willtalmadge avatar Aug 20 '23 04:08 willtalmadge

I'm now configuring Neovim on Linux with init.lua, and this works for me:

vim.g.R_assign_map = '<M-->'

I press Alt+- to get <-.

Note that the value of R_assign should be 2 only if R_assign_map is '_'.

jalvesaq avatar Aug 20 '23 11:08 jalvesaq

Just adding an update to this issue. I have tried to reproduce this behavior on other systems and I have been unable to do so and this is just a macOS issue (at least for me). Other settings seems to work as expected on macOS. While actively working in nvim :let R_assign=0 and :let R_assign=2 will produced the same issues and noted above when set in the init.vim.

I have found that if I set the default assignment of R_assign here: https://github.com/jalvesaq/Nvim-R/blob/88190144e27e14417eefd11e0a4bd91c3b9757a0/R/common_global.vim#L845 Then the expected behavior is acceived.

To the best of my understanding, if I omit the syntax enable from my init.vim file then everything works fine. Having syntax enable in init.vim is almost certainly a hold over from when I was using vim as my primary editor and not neovim. My guess on the cause of this issue is that since neovim has syntax highlighting enabled by default and vim did not, the need for syntax enable in init.vim is not needed.

Since my experience and @mikemc seem to stem from upgrading to Neovim 0.7+ (Currently I'm on 0.9.4 and testing on 0.10.0-dev-931f288) I can only conclude that having syntax enable in init.vim is the cause of the issue on macOS and the solution to the problem is to remove syntax enable from init.vim.

It is worth noting that once I'm in an active neovim session and I type :syntax enable there is no adverse behavior.

In my option, the unexpected behavior is an issue within Neovim 0.7+ and on macOS, and is outside the scope for a fix within the Nvim-R plugin.

dewittpe avatar Nov 16 '23 22:11 dewittpe

Thanks for your investigation and for solving the mystery! It seems that :syntax enable on OS X forces ftplugin scripts to be sourced and, consequently the function RCreateEditMaps() at R/common_global.vim runs with R_assign at its default value, that is, the following command is executed:

silent exe 'inoremap <buffer><silent> ' . g:R_assign_map . ' <Esc>:call ReplaceUnderS()<CR>a'

Then, when the value of R_assign is set to 0 in your init.vim it's too late because typing an underscore in Insert mode is already mapped to run the ReplaceUnderS() function.

jalvesaq avatar Nov 16 '23 22:11 jalvesaq

Other options that might be affected by the same issue are R_disable_cmds, R_user_maps_only, and R_enable_comment.

jalvesaq avatar Nov 16 '23 23:11 jalvesaq

I added a workaround for the specific issue that you have reported, but not for the other variables that might be affected by the same problem (which might be a Neovim bug on OS X).

jalvesaq avatar Nov 16 '23 23:11 jalvesaq

This seems to be similar: https://github.com/lervag/vimtex/issues/2454

jalvesaq avatar Nov 17 '23 09:11 jalvesaq

I will add a note on this in the "Know bugs" section of Nvim-R documentation...

jalvesaq avatar Dec 08 '23 10:12 jalvesaq