vim:如何连接没有空格的开/关括号

时间:2013-12-28 17:30:35

标签: join vim curly-braces

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

[
(
{
text
}
)
]

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

[ ( { text }) ]

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

2 个答案:

答案 0 :(得分:4)

您应该按gJ而不是J

:h gJ

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

根据您的要求,您可以:

:%j!

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

答案 1 :(得分:3)

: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编辑来说很方便 - 但它有很好的文档记录。