One of the things we’ve learned by from our readers is that there are a good number of folks that use Vim for non-programming related writing. A handy trick to keep your prose tidy is to use
gqto format paragraphs. Although more applicable to note taking and other writing in Vim, this trick works equally well if you’re coding. Use
gq to format paragraphs of text inside your README, some code comments, or text inside HTML.
gw– Format and wrap. Keep your cursor where it is when done.
gq– Format and wrap, but move your cursor to the end when done.
Both of these handy operations will format text based on a motion or visual selection. Here’s a screencast, showing the formatting of a paragraph:
Notice that the difference between the two is where the cursor lands. If you’d prefer your cursor stay in the the same spot in the formatted text, use
gw, if you’d like to have the cursor at the end of the paragraph, use
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?