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.
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.
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.
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.)
Or you can jump back twice (ctrl-o ctro-o)
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.