Follow

Vim quicktip #5: `gq{motion}` wraps lines to fit the configured textwidth (`:set textwidth`). If textwidth is not set, will use the screen width (with a maximum of 79).

Use `gqq` to format the current line, or `gq` in visual select mode to format all selected lines.

This is especially useful to make sure the lines in your commit messages aren’t longer than 72 characters. vim-fugitive (github.com/tpope/vim-fugitive) automatically sets the textwidth option to 72 when writing a commit message with `:Gcommit`.

@jkreeftmeijer also: "gqap" reformats the current paragraph

@judofyr I generally use a visual selection with `gq`, but actually using the motions would indeed be faster. I’ll try to get `gqap` into my muscle memory. Great addition, thanks!

Sign in to participate in the conversation
Mastodon

Follow friends and discover new ones. Publish anything you want: links, pictures, text, video. This server is run by the main developers of the Mastodon project. Everyone is welcome as long as you follow our code of conduct!