如何让Vim的`J`和`gq`命令在一段时间后使用一个空格?

时间:2011-01-21 15:19:58

标签: vim formatting

当我使用Vim的J命令时,大多数行都使用单个空格连接以进行填充。但经过一段时间后,Vim总是使用两个空格。请看以下示例:

This ends with a comma,
but this ends with a period.
Join with 'J' and what do you get?

对我来说,结果是:

This ends with a comma, but this ends with a period.  Join with 'J' and what do you get?

逗号之后的一个空格,两个之后的期间。如果使用gq命令重新格式化段落,也会出现同样的情况。

我是否可以修改设置以使Vim在句点后仅使用一个空格?

3 个答案:

答案 0 :(得分:92)

:help joinspaces


'joinspaces' 'js'    boolean    (default on)
            global
            {not in Vi}
    Insert two spaces after a '.', '?' and '!' with a join command.
    When 'cpoptions' includes the 'j' flag, only do this after a '.'.
    Otherwise only one space is inserted.
    NOTE: This option is set when 'compatible' is set.

所以,你会做一个

:set nojoinspaces

获得你想要的东西。

或者,您可以使用

切换设置
:set joinspaces!

答案 1 :(得分:24)

你需要:set nojoinspaces摆脱双重空间。 Documentation here

答案 2 :(得分:9)

:h 'joinspaces'

将此选项设置为0 / false / no。

相关问题