How do I prevent Vim from inserting two spaces after a period when joining lines with J?
Answer
:set nojoinspaces
Explanation
By default, Vim follows an old typesetting convention and inserts two spaces after a period, exclamation mark, or question mark when joining lines with J. The nojoinspaces option disables this behavior, inserting only a single space — which is the modern standard for both code and prose.
How it works
J(join) normally adds two spaces after sentence-ending punctuation (.,!,?):set nojoinspacesmakesJalways insert exactly one space, regardless of what preceded it- The option also affects
:joinand thegqformatter when joining lines - Enable permanently in your vimrc:
set nojoinspaces
Example
With joinspaces (default):
Hello world. ← cursor on this line, press J
Next sentence.
Result:
Hello world. Next sentence.
With nojoinspaces:
Hello world. Next sentence.
Tips
- This option is especially important when using
gqorgwto reformat paragraphs — double spaces can sneak in and look odd in plain text or markdown gJ(join without any inserted space) is unaffected by this option- Check the current state with
:set joinspaces?