1

In Vim wrapping lines at 80 characters without breaking words can be done with the following commands according to this article:

:set formatoptions+=w
:set tw=80
gggqG

Setting 80 char wrap is accomplished by typing gggqG after the two :set ... commands.

Is it possible to change gggqG to gqG or ggq and if so how?

The article also mentions: "Use the following mapping to format the current paragraph"

:nnoremap Q gqip

What does "mapping" mean in this case, and what are the advantages between the two approaches?

  • Of note, I prefer nnoremap Q gq (coupled with nnoremap QQ gqq) so that I can use any text objects I want. – D. Ben Knoble Jan 11 at 2:23
2

What does "mapping" mean in this case, and what are the advantages between the two approaches?

It means that when you press Q, vim reacts as if you had typed gqip. The advantage of this is that you can create whatever keyboard shortcuts you like and use vim the way that feels most naturally to you.

Is it possible to change gggqG to gqG or ggq and if so how?

Yes, absolutely. Either one of these should do it:

:nnoremap gqG gggqG
:nnoremap ggq gggqG

Also, I would recommend putting both this mapping and the

:set formatoptions+=w
:set tw=80

that you mention in your .vimrc. Basically just add all of these lines to a file named .vimrc and save it in your home directory, then vim will automatically run those commands when you launch it, so you won't need to run those commands everytime you open vim. Then you can format with just gggqG or whatever you map that to rather than typing it all out each time.

Also note that you won't need the colon if you add these lines to your vimrc. This:

set formatoptions+=w
set tw=80
nnoremap gqG gggqG

Is sufficient.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.