113

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?

5
  • 3
    Does anyone understand the rationale for this default? Jan 23, 2014 at 8:38
  • 5
    @CiroSantilli en.wikipedia.org/wiki/Sentence_spacing Apr 11, 2014 at 19:55
  • 9
    @DenilsonSá: tldr; putting two spaces between sentences used to be considered best practise, and it still is by some people.
    – Flimm
    Nov 19, 2014 at 10:43
  • @Flimm From the point of typography, putting two spaces is a bad practice. However, this can give your text editor some additional hints about how to proceed the text.
    – user90726
    Sep 10, 2021 at 11:18
  • @CiroSantilli新疆再教育营六四事件法轮功郝海东 This can give your text editor some additional hints about how to proceed the text. Emacs, for example, requires two spaces.
    – user90726
    Sep 10, 2021 at 11:19

3 Answers 3

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

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

1
  • 4
    Or in .vimrc: omit the leading colon: set nojoinspaces
    – Luc
    Jan 28, 2017 at 8:09
12
:h 'joinspaces'

Set this option to 0/false/no.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.