用vim排列函数参数列表 [英] lining up function parameter lists with vim

查看:53
本文介绍了用vim排列函数参数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用足够多的参数定义或调用函数以跨越多行时,我希望vim将它们对齐.例如,

When defining or calling functions with enough arguments to span multiple lines, I want vim to line them up. For example,

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

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

The idea is for argsN-1 to have its 'a' lined up with args1.

有人能在Vim中自动发生这种情况吗?我已经看到align插件用于衬里等号(在赋值语句中)等,但是我不确定是否可以解决该问题?

Does anyone have a way to have this happen automatically in vim? I've seen the align plugin for lining equal signs (in assignment statements) and such, but I'm not sure if it can be made to solve this problem?

推荐答案

以前的海报有它,但是忘记了 set

The previous poster had it, but forgot the 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))
                 {                         {

这篇关于用vim排列函数参数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆