Select Page

Introduction

If you primarily use Vim for all your coding tasks, you’d probably need to navigate a lot from pane to pane and file to file using just your keyboard. There’s support for mouse as well, but it sets you back from what Vim is all about – Speed and Unparalleled Efficiency.

This article will try to provide you a complete list of options and all the different ways you can navigate, which should be enough to make you forget your lovely mouse while coding and or simply just using Vim. 

(Don’t worry, the mouse that eats all your cheese every time won’t let you forget it no matter what, so keep an eye on ‘em as you learn to navigate like a pro!)

Basic Navigation


Moving By Characters

    • h – Move cursor left
    • j – Move cursor down
    • k – Move cursor up
    • l – Move cursor right
    • gj – Move cursor down in a wrapped line
    • gk – Move cursor up in a wrapped line

Moving By Words

    • w – Move to next word
    • W – Move to next blank delimited word
    • e – Move to the end of next word
    • E – Move to the end of next blank delimited word
    • b – Move to the beginning of previous word
    • B – Move to the beginning of previous blank delimited word
    • b – Move to the end of previous word
    • B – Move to the end of previous blank delimited word

Moving By Sentences

    • ( – Move a sentence back
    • ) – Move a sentence forward 
    • { – Move a paragraph back
    • } – Move a paragraph forward

Moving By Lines

    • ^ – Move to the first non-blank character of the line
    • 0 – Move to the beginning of the line
    • $ – Move to the end of the line
    • gg – Move to first line of the file
    • G – Move to the last line of the file
    • : + [number] – Move to line [number]
    • [number] + gg – Move to line [number]
    • [number] + G – Move to line [number]
    • [number] + k – Move up [number] lines
    • [number] + j – Move down [number] lines
    • ‘ ‘ – Go to the last place you were in (2 single quotes)

Character Jumping


    • fa – Jump to the next occurrence of character “a
    • Fa – Jump to the previous occurrence of character “a
    • ta – Jump to (before) the next occurrence of character “a
    • Ta – Jump to (after) the previous occurrence of character “a
    • ; – repeat the previous jump command forwards
    • , – repeat the previous jump command backwards

Changing Position on Screen


Changing the Cursor Position

    • H – Move to top of screen
    • M – Move to middle of screen
    • L – Move to bottom of screen
    • % – Move between open/close (), {}, []
    • Ctrl + f – Scroll a full screen down
    • Ctrl + d – Scroll a half screen down
    • Ctrl + b – Scroll a full screen up
    • Ctrl + u – Scroll a half screen up

Changing the Line Position

    • zt – Bring the current line to the top of screen
    • zz – Bring the current line to the middle of the screen
    • zb – Bring the current line to the bottom of the screen

Changing Cursor + Line Position

    • z + Enter – Bring current line to top of screen and reposition cursor to the beginning of line
    • z. – Bring current line to middle of screen and reposition cursor to the beginning of line
    • z- – Bring current line to bottom of screen and reposition cursor to the beginning of line

Changing the Viewport (Without altering cursor position)

    • Ctrl + y – Move screen upwards
    • Ctrl + e – Move screen downwards

Navigating between Windows


    • Ctrl + wh – move to window on left
    • Ctrl + wj – move to window below
    • Ctrl + wk – move to window above
    • Ctrl + wl – move to window on right

Navigating between Buffers


 

    • :bn – go to next buffer
    • :bp – go to previous buffer
    • :br – go to the first buffer in list
    • :bl – go to the last buffer in list
    • :b + [number] – go to buffer [number]

Go-to Navigation with G


    • gd – goto local declaration
    • gD – goto global declaration
    • gf – goto file under cursor
    • gx – goto URL under cursor
    • gi – goto last Insert Mode position
    • gI – goto beginning of line and enter Insert Mode
    • g_ – goto last non-blank character of the file
    • gm – goto middle of current line that is visible on screen
    • gM – goto middle of the entire current line

Navigating between Marks, Jumps & Changes


Marks

    • `a – jump to position of mark ‘a
    • `0 – jump to position where Vim was last exited
    • `”– jump to position of last edit on current file
    • `. – jump to position of last change in current file


Jumps

    • – go to position before last jump
    • Ctrl + i – go to newer position in jump list
    • Ctrl + o – go to older position in jump list

Changes

    • g, – go to newer position in change list
    • g; – go to older position in change list
    • Ctrl + ] – jump to the tag under cursor

Conclusion

The above listed commands should now give you an edge over your day to day text manipulation tasks in Vim. If you’re a hardcore Vim user, you would probably want to know it all by heart. As a Vim user myself, I could probably tell you how good it is to not have to use a mouse for navigation (I used to be one of those people who clicked tabs with the mouse back when I was in VS Code). It’s extremely inefficient as compared to what you could achieve with a little knowledge about navigation in Vim!