I'd like it if, when filling out my Roxygen comment snippet,

#' Title     
#' @param    
#' @return   
#' @examples 
#' @export   

vim would extend the #' when I press return on a line.

I figure I need to do something with :setlocal comments, but I haven't been able to figure out what.

1 Answer 1


Create the file ~/.vim/after/ftplugin/r.vim (Windows: $HOME/vimfiles/after/ftplugin/r.vim) with the following content:

setlocal formatoptions+=r

This file is sourced, after Vims filetype specific file for R is sourced. So it can be used to change settings that are from the R file type plugin or to add other things that you want to do when loading a R file (like define specific mappings etc).

If you only want to change the formatoptions you could also add the following to your vimrc:

autocmd FileType r setlocal formatoptions+=r

The added formatoption r means:

Automatically insert the current comment leader after hitting <Enter> in Insert mode.

  • Thank you! The equivalent file in neovim is ~/.config/nvim/after/ftplugin/r.vim.
    – brandones
    Commented Feb 7, 2019 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.