Prevent R code autocomplete for "%>%" in Visual Studio Code from suggesting "%in%"

248 Views Asked by At

When using the R Extension for Visual Studio Code the code completion always suggests %in% for a line that ends with the magrittr pipe %>%. The final % in %>% triggers an autocomplete suggestion of %in%.

Here's what happens when writing a code block:

library(dplyr)
mtcars %>%
    select(mpg, cyl) %>%

enter image description here

Is there anyway to fix this? If I type "enter" for a newline like I normally would in any other text editor, visual studio code inserts the %in% at the end of the line, which clearly isn't what I want.

I'm not sure where I can tweak any configurations - whether in visual studio code, or the R extension, or the R language server.

2

There are 2 best solutions below

0
PejoPhylo On BEST ANSWER

Since the accepted answer isn't useful (whereas MangoHands comment is), I'm reposting his comment as a separate answer:

You can disable the acceptance of suggestions via the enter button which and instead use (only) tab to accept suggestions, which I find intuitive.

To this end add the following line into the Preferences: Open User Settings (JSON) option from visual studio (Use Ctrl+Shift+P/Cmd+Shift+P to open the command palette and search for Preferences: Open User Settings (JSON)):

"editor.acceptSuggestionOnEnter": false

PS: Using the shortcut for the pipe (Cmd+Shift+M) is cute until you realize that it won't work in the terminal - at least noy in radian- (instead you shift to the 'problems' tab), which for me is a huge and annoying issue.

1
MarBlo On

Try this in your settings.json. It should prevent from suggestion of unnecessary strings comments and also %>% or %in%.

  "[r]": {
    "editor.quickSuggestions": {
      "other": false,
      "comments": false,
      "strings": false
    }
  }