Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

formatting

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?

like image 777
nelstrom Avatar asked Jan 21 '11 15:01

nelstrom


3 Answers

: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!
like image 188
René Nyffenegger Avatar answered Nov 18 '22 20:11

René Nyffenegger


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

like image 30
Kevin Lacquement Avatar answered Nov 18 '22 19:11

Kevin Lacquement


:h 'joinspaces'

Set this option to 0/false/no.

like image 12
Luc Hermitte Avatar answered Nov 18 '22 20:11

Luc Hermitte