How can I make Vim's `J` and `gq` commands use one space after a period?

VimFormatting

Vim Problem Overview


When I use Vim's J command, most lines are joined with a single space for padding. But after a period Vim always uses two spaces. Take the following example:

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

For me, the result is:

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

One space after the comma, two after the period. Same story if you reformat the paragraph with the gq command.

Is there a setting that I can modify to make Vim use only one space after the period?

Vim Solutions


Solution 1 - Vim

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

Solution 2 - Vim

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

Solution 3 - Vim

:h 'joinspaces'

Set this option to 0/false/no.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnelstromView Question on Stackoverflow
Solution 1 - VimRené NyffeneggerView Answer on Stackoverflow
Solution 2 - VimKevin LacquementView Answer on Stackoverflow
Solution 3 - VimLuc HermitteView Answer on Stackoverflow