【问题标题】:vim: How to join open/close braces without white spacesvim:如何在没有空格的情况下加入开/关大括号
【发布时间】:2013-12-28 17:30:35
【问题描述】:

我对花括号的格式有点困惑。假设我有以下文字:

[
(
{
text
}
)
]

要加入所有行,我按JJJ... 得到:

[ ( { text }) ]

这是正常行为吗?为什么 vim 不加入 ( 没有空格,而它会抑制 ) 的空格?

【问题讨论】:

    标签: join vim curly-braces


    【解决方案1】:

    你应该按gJ 而不是J

    :h gJ

    还有:join 命令。你需要阅读:h join

    根据您的要求,您可以:

    :%j!

    或首先选择行,然后: :'<,'>j!(vim会自动填充'<,'>的范围)

    【讨论】:

    • 感谢您的回复,但有时行也会缩进。 gJ 将涉及这些我不想要的缩进空格。我知道:h fo-table 中列出的一些选项可以在加入文本时控制空白(例如fo+=B),但我不明白为什么) 是特殊的而( 不是。
    【解决方案2】:

    来自:help J(向下滚动一点,或者从:help replacing向上滚动一点):

    These commands, except "gJ", insert one space in place of the <EOL> unless
    there is trailing white space or the next line starts with a ')'.  These
    commands, except "gJ", delete any leading white space on the next line.
    

    我不确定它为什么会这样工作——也许它便于 C 编辑——但它有据可查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-16
      • 2012-05-03
      相关资源
      最近更新 更多