vim - 在 Vim 中按括号列索引缩进代码?

标签 vim erlang indentation

我正在使用 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/

相关文章:

formatting - 同时在多行中添加空格 - 在 Pycharm 中

vim - VIM中是否有 block 撤消功能?

unix - 我应该学习什么Unix文本编辑器?

linux - git 子模块已经存在但它不存在?

erlang - 如何解耦然后重构 Erlang 进程 PID <A.B.C>

intellij-idea - Erlang无法在intellij中运行

erlang - gen_server 中的数据被其主管重新启动后会保留吗?

vim - 如何不通过插入 `#` 来删除缩进?

javascript - 我怎样才能让 Vim 得到正确的 JS 缩进?

google-chrome - Vim:随时刷新 chrome :write