Rahul Goel


Markup Formatting using gq

Posted on: June 12, 2021

It had been such a pain to format lines when I was writing Latex/Markdown/HTML. Since single line breaks are ignored, we can write all that we have to in a single line or multple lines. Writing in a single line always makes it tough to read later in a text editor. Since sentences are broken in between words and you have to move your eyes all across the screen. And if you want to use multiple lines, it is tough to decide where to break the lines manually. If you follow the 79 character limit, it is again hard to keep track of the characters.

But with the gq family of commands in vim, now I write everything in a single line and then run the gqq key bind to autoformat the text into multiple lines. One can also write in any haphazard manner in multiple lines and then visually select them and run gq to format them again. By default it follows the 79 character limit but it can be changed in the vimrc.

It is a command every Vim user should use to simplify writing markup text anywhere.

Below is this blog written in markdown in Vim - first without the formatting and then with the formatting.

1 # Markup Formatting using `gq`
2 
3 It had been such a pain to format lines when I was writing Latex/Markdown/HTML.  Since single line breaks are ignored, we can write all that we have to in a single line or multple lines. Writing in a single line always makes it tough to read later in a text editor. Since sentences are broken in between words and you have to move your eyes all across the screen. And if you want to use multiple lines, it is tough to decide where to break the lines manually. If you follow the 79 character limit, it is again hard to keep track of the characters.
4 
5 But with the `gq` family of commands in vim, now I write everything in a single line and then run the `gqq` key bind to autoformat the text into multiple lines. One can also write in any haphazard manner in multiple lines and then visually select them and run `gq` to format them again. By default it follows the 79 character limit but it can be changed in the vimrc.
6 
7 It is a command every Vim user should use to simplify writing markup text anywhere.
8 
9 Below is this same blog written in Vim
 1 # Markup Formatting using `gq`
 2 
 3 It had been such a pain to format lines when I was writing Latex/Markdown/HTML.
 4 Since single line breaks are ignored, we can write all that we have to in a
 5 single line or multple lines. Writing in a single line always makes it tough to
 6 read later in a text editor. Since sentences are broken in between words and
 7 you have to move your eyes all across the screen. And if you want to use
 8 multiple lines, it is tough to decide where to break the lines manually. If you
 9 follow the 79 character limit, it is again hard to keep track of the
10 characters.
11 
12 But with the `gq` family of commands in vim, now I write everything in a single
13 line and then run the `gqq` key bind to autoformat the text into multiple
14 lines. One can also write in any haphazard manner in multiple lines and then
15 visually select them and run `gq` to format them again. By default it follows
16 the 79 character limit but it can be changed in the vimrc.
17 
18 It is a command every Vim user should use to simplify writing markup text anywhere.