我正在使用Vim-R-plugin和Vim为我的R代码提供语法高亮.常规缩进样式在括号开头的函数中对齐参数.我想将其更改为更像花括号内的代码,其中新行缩进两个空格而不是用花括号内联.
我的函数名称往往是冗长的,默认缩进样式会将所有参数一直推到屏幕右侧.
以下是一些例子:
# Default indentation style
result <- fun(
par1 = "abc",
par2 = "def",
par3 = 3
)
Run Code Online (Sandbox Code Playgroud)
所需的样式模仿for循环和函数定义的缩进样式.
# 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)
}
Run Code Online (Sandbox Code Playgroud)
我查看了Vim-R-plugin代码,但它太密集了,我无法理解.有没有办法让我改变它?
如果有人在寻找这个问题:
:help r-plugin-indenting
Run Code Online (Sandbox Code Playgroud)
简短的回答.在.vimrc中,添加以下行:
" 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
Run Code Online (Sandbox Code Playgroud)
缩进将类似于OP所描述的.
首先看一下:help 'cindent'和;:help 'smartindent'您可以使用这两个选项之一相对轻松地配置缩进。您也可以尝试编写自己的indentexpr,但这有点高级。这需要放弃 Vim-R 插件,转而使用 Vim 原生的缩进解决方案。