5 Comments
User's avatar
bobbyquine_'s avatar

To add on: oftentimes people lose where they were after they use gg=G. Another nice trick would be to save your current position in a mark first (, say, "mx"), then "gg=G", then jump back to mark with "`x" (that's a back-tick). Note that x can be any letter.

Andrew Libby's avatar

Great suggestion, thanks! There are also jumps you can use. If you [ctrl]-o twice after this you should be back at your starting position.

Rich Cheng's avatar

No need to set an alphabetical mark. You can use one that Vim sets for you. Try `` instead. (Vim automatically sets this mark whenever you jump.)

Raman Walwyn-Venugopal's avatar

Or you can jump back twice (ctrl-o ctro-o)

lunik1's avatar

I think the usefulness of this varies on the language. In most cases you are better of setting up an LSP if able, setting formatexpr, and using gq.