8 Essential Vim Editor Navigation Fundamentals

  1. Line navigation
  2. Screen navigation
  3. Word navigation
  4. Special navigation
  5. Paragraph navigation
  6. Search navigation
  7. Code navigation
  8. Navigation from command line

1. Vim Line Navigation

  • k — navigate upwards
  • j — navigate downwards
  • l — navigate right side
  • h — navigate left side

By using the repeat factor in VIM we can do this operation for N times. For example, when you want to
go down by 10 lines, then type “10j”.

Within a line if you want to navigate to different position, you have 4 other options.

  • 0 — go to the starting of the current line.
  • ^ — go to the first non blank character of the line.
  • $ — go to the end of the current line.
  • g_ — go to the last non blank character of the line.

2. Vim Screen Navigation

  • H — Go to the first line of current screen.
  • M — Go to the middle line of current screen.
  • L — Go to the last line of current screen.
  • ctrl+f — Jump forward one full screen.
  • ctrl+b — Jump backwards one full screen
  • ctrl+d — Jump forward (down) a half screen
  • ctrl+u — Jump back (up) one half screen

3. Vim Special Navigation

  • N% — Go to the Nth percentage line of the file.
  • NG — Go to the Nth line of the file.
  • G — Go to the end of the file.
  • `” — Go to the position where you were in NORMAL MODE while last closing the file.
  • `^ — Go to the position where you were in INSERT MODE while last closing the file.
  • g — Go to the beginning of the file.

4. Vim Word Navigation

  • e — go to the end of the current word.
  • E — go to the end of the current WORD.
  • b — go to the previous (before) word.
  • B — go to the previous (before) WORD.
  • w — go to the next word.
  • W — go to the next WORD.

WORD — WORD consists of a sequence of non-blank characters, separated with white space.
word — word consists of a sequence of letters, digits and underscores.

Example to show the difference between WORD and word

  • 192.168.1.1 — single WORD
  • 192.168.1.1 — seven words.

5. Vim Paragraph Navigation

  • } — Go to the end of the current paragraph. By pressing } again and again move to the next paragraph end, and again.

6. Vim Search Navigation

  • ?i — Search for a pattern which will you take you to the previous occurrence of it.
  • * — Go to the next occurrence of the current word under the cursor.
  • # — Go to the previous occurrence of the current word under the cursor.

7. Vim Code Navigation

8. Vim Navigation from Command Line

vim +10 /etc/passwd

Vim +/pattern filename: Go to the particular pattern’s line inside the file, first occurrence from first. In the following example, it will open the README file and jump to the first occurrence of the word “install”.

vim +/install README

Vim +?patten filename: Go to the particular pattern’s line inside the file, first occurrence from last. In the following example, it will open the README file and jump to the last occurrence of the word “bug”.