Functions

Instead of doing the basic flow of str() + plot() , etc…Nvim-R allows for a simplified flow.

summary() :: \rs

plot() :: \rg

args() :: \ra

setwd() :: \rd

print() :: \rp

names() :: \rn

Arrows

Arrows can be a pain to type. Luckily, Nvim-R makes it easier by mapping _ to <- . This may, or may not, completely bewilder you. If you’re someone who prefers snake case, then you’ll have to hit the underscore twice in order to get an actual underscore, and not an arrow. However, you can override this setting. I find it useful, and have adjusted, but can certainly understand others being irked.

Completion

Often I see lack of code completion as a major reason people skip Vim. This notion is incorrect though. Code completion is very much apart of Vim. For our specific purpose, namely completion for R, there are, yet again, a few options.

Nvim-R Completion

Nvim-R supports code completion out of the box. You will have to manually engage it by using <C-X><C-O> for an object name, or <C-X><C-A> for a function argument. For some people this workflow is ideal, but in the current age of VS Code’s Intellisense, and other such options, this feels clunky.

Ncm-R

Ncm-R is your best bet for as-you-type sort of completions. It’s a fairly new package, but a much welcomed addition. It integrates with Nvim-R to provide asynchronous completions for R via nvim-completion-manager.

Ncm-R provides rich completions for all of the following:

Objects from the global R environment

Functions from all loaded packages

Packages inside library() and require()

and Datasets inside data()

Arguments inside functions

Variables inside pipes %>% and ggplots +

For a basic set up add the code below to your Vim configuration file.

Plug ‘roxma/nvim-completion-manager’

Plug ‘gaalcaras/ncm-R’ “ Optional: for snippet support

Plug ‘sirver/UltiSnips’

R Language Server

If you are unfamiliar with what a language server is head here. If you are familiar, then this project may be of interest. It is still in the early days, and largely experimental, but does work and currently supports both code completion and linting.

Linting

Last but not least, linting. The set up for quality linting is fairly straightforward. You’ll want to use ALE, Asynchronous Lint Engine, as your driver. You can set this up in your .vimrc as follows:

Plug ‘w0rp/ale’

Now all you need to do is install lintr. This can be done by using install.packages(‘lintr’) .

Now, the next time you open up an .R file you should be good to go.

Conclusion

At this point, you have a killer set up for R in Vim. There is certainly more to do though if you’re curious. Areas for further exploration include looking through all of the documentation in the plugins I have linked throughout this article. You’ll find many helpful tips and tricks in there, as well as useful settings. I hope this helped to get you up and running with R in Vim!

For more about Vim head to my blog!