How to keep white spaces when to format text with fixed width?

202 Views Asked by At

To set line to be 100 characters for the edited text as below.

:set textwidth=100
gggqG

I found that all lines set 100 characters but all the white spaces deleted.
How to keep all white spaces at the same time to set width 100 for every line?

1

There are 1 best solutions below

0
Ingo Karkat On

Vim's built-in formatter keeps multiple spaces inside text; these only get truncated when Vim breaks the line right there.

As for indent (whitespace at the beginning of the line), the first (or with 2 in 'formatoptions', second) line determines the indent for the reformatted block.

In general, this setting makes sense. If you have special formatting needs, you can instruct Vim to either use an external formatter that does the job (:help 'formatprg'), or write your own in Vimscript (:help 'formatexpr').