3 ms·
A couple of nice ones: `gq` for re-wrapping a visually selected block of text (<shift>-v is simplest) to your text width. `=` for re-indenting a selection to y
by amaterasu 8y ago
A couple of nice ones:
`gq` for re-wrapping a visually selected block of text (<shift>-v is simplest) to your text width.
`=` for re-indenting a selection to your current shift-width settings etc. (or `gg=G` to just do the whole file)
- Xophmeister 8y ago`gq` will work with a text object, so you don't need to go to the trouble of visually selecting a block. Say, for example, you have a mis-wrapped paragraph in a text file, providing your cursor is anywhere within that paragraph, `gqip` will rewrap the whole paragraph.
- wyoung2 8y agoThe nice thing about using `=` instead of `gq` is that you can “set equalprg” to something smarter than the internal Vim formatter, such as `fmt` or `par`: https://www.gnu.org/software/coreutils/manual/coreutils.html#fmt-invocation http://www.nicemice.net/par/ These formatters will do nice things like choose line breaks intelligently to reduce the raggedness of the right edge. I just tested `gqip` on a paragraph in a Markdown document here that was formatted with `fmt`: the `fmt` output put breaks in such that all but the last line was within one character of equal, whereas `gqip` had line lengths varying as much as 5 characters on a 72 character line length. A quicker alternative to Shift-V, arrows, then `=` to reformat a paragraph with `fmt` is this: :map <F2> !}fmt -w72<CR> That works anywhere inside the paragraph like with your `gqip`, but it uses the smarter `fmt` paragraph formatter. Select your keystroke to taste. I chose F2 so long ago that I forget why that was a good idea at the time.