Vim: underscore(_) automatically converted to (<-)
Asked Answered
P

5

6

I have been writing R scripts in Vim for some time now. Starting an hour ago, I began facing an issue that every time I type an underscore (_), it gets automatically converted to <-.

What setting did I change for this to happen? Thanks!

Prevaricator answered 13/3, 2014 at 13:59 Comment(0)
D
7

:verbose imap _ should tell you which (probably filetype plugin) has set this.

It's less likely to be an abbreviation, but :verbose ia _ would tell you.

Darelldarelle answered 13/3, 2014 at 14:6 Comment(1)
And in case you don't know your history, _ used to be the assignment operator in S (and then R). So x_5 was like x<-5, and so emacs' ESS and Vim's R plugin implement this replacement to help us old timers and annoy the hadley_fan_bois :)Chasechaser
G
6

The VIM: r-plugin does indeed change the mapping but the documentation section 4.1 states "it is possible to insert an actual underscore into your file by typing a second underscore".

Thus, while you can disable the conversion of _ to <- it is easy to override temporarily.

Granivorous answered 2/10, 2015 at 9:9 Comment(0)
V
1

It may be also worthwhile to add that a convenient setting may involve re-assigning the operator, for instance the .vimrc setting:

" Nvim-R extra settings
"" Change assignment operator
let R_assign_map = "|"

Would assign the assignment operator <- to Shift+|. This feature is described ithe provided documentation. In the R_assign section.

Vickers answered 19/12, 2016 at 9:10 Comment(0)
G
1

To add more options to what you can do, Nvim-R has not only R_assign_map as @konrad pointed out, but R_assign which manages how the feature works. A previous answer on duplicate answer mentioned an outdated version of R_assign (older name) being set to 0 as the answer.

I have found that the actual way to use this variable as of at least this post date (while the variable is still called R_assign) that there are 2 valid values thus 3 functions. I have only tried values of -1 to 3, but I found 1 and 2 to produce something, so here they are:

  • Invalid values (let R_assign=-1 (anything but 1 and 2)) made it so that _ produced <- and any subsequent _ keys produced more <-
  • let R_assign=1 produced the default documented behaviour of 1 _ makes a <- and the next _ makes (thus two _) a single _
  • let R_assign=2 flips it so that a single _ makes _ and another _ makes a <- (so two _ for a <-)
Gramineous answered 11/6, 2017 at 4:55 Comment(0)
F
0

Add this to ~/.vimrc:

let R_assign = 0

Close and reopen nvim and _ will work as expected.

Source: here.

Featherhead answered 1/3 at 3:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.