用vim排列函数参数列表

时间:2008-09-18 00:34:39

标签: vim editor whitespace

当定义或调用具有足够参数的函数来跨越多行时,我希望vim将它们排成一行。例如,

def myfunction(arg1, arg2, arg, ...
               argsN-1, argN)

这个想法是让argsN-1的'a'与args1对齐。

有没有人有办法在vim中自动发生这种情况?我已经看到了对齐插件用于衬平等号(在赋值语句中)等等,但我不确定是否可以解决这个问题?

4 个答案:

答案 0 :(得分:11)

上一张海报有,但忘记了set

:set cino=(0<Enter>

来自:help cinoptions-values

The 'cinoptions' option sets how Vim performs indentation.  In the list below,
"N" represents a number of your choice (the number can be negative).  When
there is an 's' after the number, Vim multiplies the number by 'shiftwidth':
"1s" is 'shiftwidth', "2s" is two times 'shiftwidth', etc.  You can use a
decimal point, too: "-0.5s" is minus half a 'shiftwidth'.  The examples below
assume a 'shiftwidth' of 4.

...

    (N    When in unclosed parentheses, indent N characters from the line
          with the unclosed parentheses.  Add a 'shiftwidth' for every
          unclosed parentheses.  When N is 0 or the unclosed parentheses
          is the first non-white character in its line, line up with the
          next non-white character after the unclosed parentheses.
          (default 'shiftwidth' * 2).

            cino=                     cino=(0 >
              if (c1 && (c2 ||          if (c1 && (c2 ||
                          c3))                     c3))
                  foo;                      foo;
              if (c1 &&                 if (c1 &&
                      (c2 || c3))           (c2 || c3))
                 {                         {

答案 1 :(得分:7)

我相信你必须发出命令:

:set cino=(0

这当然是在使用cindent时。

编辑:我错过了“设置”

答案 2 :(得分:2)

答案 3 :(得分:1)

使用特定于语言的外部工具作为Vim过滤器可能会获得一些好处。例如,如果你可以写一个Perltidy配置文件来生成你想要的格式(看起来你想要 -lp -vtc = 2 标志),你可以管道你的现有的Vim缓冲区通过它

:!/path/to/tidy -config /path/to/configfile

如果您要经常运行此类命令,可以通过在.vimrc中添加以下内容来定义命令:

command -range=% Tidy <line1>,<line2>!/path/to/tidy -config /path/to/configfile