vimtricks.wiki Concise Vim tricks, one at a time.

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 nojoinspaces makes J always insert exactly one space, regardless of what preceded it
  • The option also affects :join and the gq formatter 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 gq or gw to 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?

Next

How do I prevent Vim from adding a newline at the end of a file when saving?