DEV Community

Vasily Polovnyov
Vasily Polovnyov

Posted on

gg=G`` — my favourite Vim command

I found myself writing code without paying attention to formatting: let it be written as it is written, Vim will format it later. And the easiest and fastest way to do this is to format the whole file: gg=G``.

gg moves cursor to beginning of file. =G formats the code from the cursor to the end of the file. `` brings the cursor back.

Top comments (1)

pbnj profile image
Peter Benjamin (they/them) • Edited

Also, gq is similar to =. Example: gggqG

The behavior of = and gq are customizable via equalprg and formatprg options respectively.

See, :help =, :help equalprg, :help gq, :help formatprg for more info.