I'm using the Vim-R-plugin with Vim to provide syntax highlighting for my R code. The regular indentation style aligns parameters in a function at the opening of the parentheses. I'd like to change this to be more like code within curly braces, where new lines are indented two spaces instead of inline with the curly braces.
My function names tend to be verbose and the default indentation style leaves all my parameters pushed all the way to the right of the screen.
Here's some examples:
# Default indentation style
result <- fun(
par1 = "abc",
par2 = "def",
par3 = 3
)
The desired style mimics the indentation style for for
loops and function definitions.
# Desired indentation style
result <- fun(
par1 = "abc",
par2 = "def",
par3 = 3
)
# Similar to for loop indentation
for(i in 1:10) {
print(i)
}
# ... and function definitions
fun <- function(par1 = 1) {
print(par1 + 1)
}
I looked at the Vim-R-plugin code but it's too dense for me to understand. Is there a way for me to change it?
If someone looks for this question:
:help r-plugin-indenting
Short answer. In .vimrc, add those lines :
" set vim-r-plugin to
let r_indent_align_args = 0
" Set vim-r-plugin to mimics ess :
let r_indent_ess_comments = 0
let r_indent_ess_compatible = 0
Indentation will be like described by OP.
Take a look at :help 'cindent'
and :help 'smartindent'
for starters; you can configure indentation relatively easily using either of these two options. You could also try writing your own indentexpr
, but that's getting a bit advanced. This would require ditching the Vim-R plugin in favour of a Vim-native indentation solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With