2

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.

3

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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