Skip to content

Enable Nvim R for any file type

Jakson Alves de Aquino edited this page Sep 11, 2023 · 2 revisions

Nvim-R is a file-type plugin. This means that its functionalities will be available only when an R file type is being edited (R, Rnoweb, Rhelp, Rmd, etc). However, if you need to run R with other file types, you can put in your vimrc:

command RStart let oldft=&ft | set ft=r | exe 'set ft='.oldft | let b:IsInRCode = function("DefaultIsInRCode") | call StartR("R")

The above Vim line will create the Normal mode command :RStart which when run will:

  1. Set the file-type of the buffer being edited as "r" and, consequently, enable Nvim-R.

  2. Set the file-type back to its original value.

  3. Avoid an internal error when you type "_".

  4. Start R.