Vim newbie here. How can I hard wrap plain text in vim (inserting actual linebreaks), respecting word boundaries, without joining existing lines?
For example, given this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
- Nulla cursus accumsan faucibus.
- Donec dapibus dignissim ullamcorper.
Integer
nec
malesuada
diam.
I'd like to get (with textwidth=30):
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
- Nulla cursus accumsan
faucibus.
- Donec dapibus dignissim
ullamcorper.
Integer
nec
malesuada
diam.
instead of this (which I can get with gggqG
)
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
- Nulla cursus accumsan
faucibus.
- Donec dapibus dignissim
ullamcorper.
Integer nec malesuada diam.
Also, for bonus points: when I create a brand new buffer, I get different wrapping behavior (lines beginning with – aren't wrapped specially) than when I open a file ending in .txt. What controls this? I don't notice any difference in the output of :set filetype?
or :filetype
.
Best Answer
To the first question, use
That will execute
gqq
on each line individually.I don't know the answer to the second question, but it could be the result of an autocommand triggered by the .txt suffix that changes
'formatoptions'
or'comments'
without setting the'filetype'
. You can executeto see where those options were set last. Some GNU/Linux distributions put their own Vim configuration commands in /etc/vimrc or /usr/share/vim/vimrc.