Here are some commands you can use in Normal mode to move within the current file:

  • gg move to the first non-blank character of the first line
  • G move to the first non-blank character of the last line
  • 5G move to the first non-blank character of the fifth line
    • As an alternative, you can use :5 followed by Enter key (Command-line mode)
  • 50% move to the halfway point
    • you can use other percentages as needed
  • % move to matching pair of brackets like (), {} and []
    • This will work across lines and nesting is taken into consideration as well
    • If the cursor is on a non-bracket character and a bracket character is present later in the line, the % command will move to the matching pair of that character (which could be present in some other line too)
    • Use the matchpairs option to customize the matching pairs. For example, :set matchpairs+=<:> will match <> as well

info It is also possible to match a pair of keywords like HTML tags, if-else, etc with %. See :h matchit-install for details.

Video demo:


info See also my Vim Reference Guide and curated list of resources for Vim.