如何让 Vim 的“ J”和“ gq”命令在句号后使用一个空格?

当我使用 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 只使用一个空间后的时期?

7505 次浏览
:h 'joinspaces'

Set this option to 0/false/no.

You need to :set nojoinspaces to get rid of the double space. Documentation here

: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.

So, you would do a

:set nojoinspaces

to obtain what you desire.

Alternatively, you can toggle the setting with

:set joinspaces!