2011-11-22 149 views
3

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

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 

我所要求的是不同fN因为fN对齐到流行缩进,并且我想要对齐任何直接在op之前的C++ nested-name-specifier付民(,像

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

如果没有nested-name-specifier,我想它匹配(本身。也许匹配一个nested-name-specifier太复杂了,或者也许有另一个语法的部分,这更适合于这种情况。无论如何,对于我的典型用例,我认为如果{与最内部未封闭的((含)之间的最大字符序列的第一个非空白字符对齐,该字符不包含任何分号或左卷大括号}

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

+0

尝试'设置nocindent',为我工作 - !但我有还有smartident和autoindent开启 – Zaffy

回答

0

不确定是否有{自动,智能,c}缩进功能可以按照您的要求做。我做了这可能给一些启示的映射:

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

缺点是,你可能需要做的不是“T”聪明的东西,回到过去的标识符(你可以使用与年初“?”一个正则表达式),它会破坏你的默认寄存器,并且如果你的标识符在paren之前是在你开始行的时候你必须做的({'你自己。这个概念是跳回到标识符之前,复制到该行的开头,粘贴到下一行,并用空格代替每一个角色

好运