3

在 vim(例如 7.3)中,我如何使用/修改cindentorsmartindent选项,或以其他方式增加 my .vimrc,以便在开括号内自动缩进大括号以与直接在开头之前的第一个“单词”(稍后定义)对齐(

该选项似乎很有希望,但在开括号内时fN似乎被该选项覆盖。(N来自:help cinoptions-values

fN    Place the first opening brace of a function or other block in
      column N.  This applies only for an opening brace that is not
      inside other braces and is at the start of the line.  What comes
      after the brace is put relative to this brace.  (default 0).

        cino=           cino=f.5s       cino=f1s
          func()          func()          func()
          {                 {                 {
              int foo;          int foo;          int foo;

当前行为:

func (// no closing ) 
      // (N behavior, here N=0      
      {    // (N behavior overrides fN ?
        int foo; // >N behavior, here N=2 

虽然我希望:

func (// no closing )   
      // (N behavior as before   
{ // desired behavior
  int foo; // >N behavior still works

我所要求的不同于因为与普遍缩进对齐,并且我想与直接在开头之前的任何 C++fN对齐,例如fNnested-name-specifier(

code; f::g<T> (         instead of         code; f::g<T> (
      {                                    { 

如果没有nested-name-specifier,我希望它与(自身匹配。也许匹配 anested-name-specifier太复杂了,或者语法的另一部分更适合这种情况。无论如何,对于我的典型用例,我认为如果{与最里面的 unclosed ((包括在内)不包含任何分号或左花括号的最大字符序列的第一个非空白字符对齐,我会感到满意}

顺便说一句,我在尝试std::for_each(b,e,[]{});在 vim7.3 中自动缩进各种结构时遇到了这个问题。谢谢你的帮助!

4

1 回答 1

0

不确定是否可以将任何 {auto,smart,c} 缩进功能调整为您想要的。我制作了一个可能会带来一些启发的映射:

inoremap ({ <esc>T<space>y0A<space>(<cr><esc>pVr<space>A{

缺点是您可能需要做一些比“T”更聪明的事情才能回到最后一个标识符的开头(您可以使用“?”与正则表达式),它会破坏您的默认寄存器,并且如果您的标识符之前paren 在你必须自己做的行的开头 '({' 。这个概念是跳回到标识符之前,复制到行首,将其粘贴到下一行,并将每个字符替换为空间。

祝你好运!

于 2014-09-17T13:53:17.117 回答