Navigating around the screen
Vim has numerous key mappings for moving around the screen. Some of these you might not know about or might not be a part of your regular muscle memory.
The following mappings all move the cursor around the screen without shifting the viewport. That is, the lines stay in place, but the cursor moves. These are really useful for moving through text such as prose, markdown, READMEs, etc. In those types of files you don’t have method/function navigation.
H
– Move cursor to the first line on the screen (mnemonic: “High”)M
– Move cursor to the middle line on the screen (mnemonic: “Middle”)L
– Move cursor to the last line on the screen (mnemonic: “Low”)
The next set move the viewport — the cursor stays where it’s at, but the lines behind it move. Generally these are useful for getting a better view of the surrounding text or jumping quickly through a document when you don’t know what you’re looking for.
<ctrl-f>
– Move viewport forward one full screen (mnemonic: “Forward”)<ctrl-b>
– Move viewport backwards one full screen (mnemonic: “Backward”)<ctrl-d>
– Move viewport down one half screen (mnemonic: “Down”)<ctrl-u>
– Move viewport up one half screen (mnemonic: “Up”)
Related, check out two other tips we’ve written about before:
- Reposition the current line with
zt
,zz
, andzb
. - Nudge the current line up or down with
<ctrl-e>
or<ctrl-y>
.