我正在使用 Vim 来编辑 Erlang 代码。我习惯于(大多数 Erlang 程序员都这样做)通过他们所在的括号范围缩进 Erlang 代码。 例如,C 通常在大括号内缩进一个制表符宽度:
int main(void) {
printf("hello, world\n");
return 0;
}
在 Erlang 中,根据括号开始的列缩进是很常见的:
?assertError({bad_options, [{foo, bar},
bad_option]},
lhttpc:request("http://localhost/", get, [], <<>>, 1000,
[bad_option, {foo, bar}])).
(上面的例子是缩进的,而不是根据主观美感)。
如果块在新行上开始,将使用制表符宽度:
?assertError(
{bad_options, [{foo, bar}, bad_option]},
lhttpc:request(
"http://localhost/", get, [], <<>>, 1000,
[bad_option, {foo, bar}]
)
).
我的 .vimrc 的相关部分:
set expandtab " Spaces for tabs "
set tabstop=4 " Tab width 4 "
set shiftwidth=4
set smarttab
set autoindent
" Enable filetype plugin "
filetype plugin on
filetype indent on
有没有办法在 Vim 中执行这种缩进,如果是这样,如何?
最佳答案
有一个 vimerl 的分支,它实现了“上下文感知缩进”而不是“静态缩进”:https://github.com/aszlig/vimerl.git
似乎有效,所以我会继续使用一段时间。
关于vim - 在 Vim 中按括号列索引缩进代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7330761/