5

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!

Joshua
  • 40,822
  • 8
  • 72
  • 132
tejas_kale
  • 593
  • 2
  • 7
  • 21

4 Answers4

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.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 10
    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 :) – Spacedman Mar 13 '14 at 15:00
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.

Community
  • 1
  • 1
stegzzz
  • 407
  • 4
  • 9
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.

Konrad
  • 17,740
  • 16
  • 106
  • 167
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 <-)
Boris N
  • 33
  • 5