DEV Community

loading...

gg=G`` — my favourite Vim command

vasily profile image Vasily Polovnyov ・1 min read

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.

Discussion (1)

pic
Editor guide
Collapse
pbnj profile image
Peter Benjamin • 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.