Vim / Vi Page Up and Down Controls
Glory Kim
Software Engineer, Loom
Published: 1/31/2024
While the most intuitive way to navigate around the terminal may be scrolling and using the arrow keys, Vim offers multiple shortcuts to move around the screen. Paging up and down with keyboard shortcuts is one of the most efficient and flexible ways to hop around. To start, make sure that you are not in Insert mode and that you are in Normal mode by pressing ESC.
Page up and down
A page is considered to be the screen size of your terminal. The following commands will move the page up and down based on the current screen size.
- ctrl + b to move a page screen back or “up”
- ctrl + f to move a page screen front or “down”
- ctrl + u to move a ½ page screen up
- ctrl + d to move a ½ page screen down
Row up and down
To move up and down a single row instead of a whole page:
- j to move 1 line down
- k to move to move 1 line up
Similar to how you navigated to specific rows, we can leverage this command to move up and down multiple rows.
- 2j to move 2 lines down
- 2k to move 2 lines up
Caveat
As an engineer, I use the above commands when I’m reading through code and don’t care about cursor placement. The above commands can move the screen so that I can read my entire file, but they also alter my cursor location. When I’m writing code and want to understand related functions, I tend to use other commands to keep my cursor in place. As long as my cursor does not go off-screen, I can remember my current spot while reading through the file.
- ctrl + y to move the screen up one line
- ctrl + e to move the screen down one line
- z + z to move the current line I’m on to the center of the screen
- z + t to move the current line I’m on to the top of the screen
- z + b to move the current line I’m on to the bottom of the screen
Other ways to Vim
This post lists out just a couple of ways to navigate your terminal using Vim like viewing pages and rows. A related way to navigate is to use vim to go to the beginning and end of the file. Learning how to navigate is just the beginning: with vim, you’re able to copy and paste, undo and redo, and delete line(s) all with just a few keystrokes.
Written by
Glory Kim
Software Engineer, Loom
Filed Under
Related Articles
Vim Find And Replace
You can use either the substitute command or the slash and dot method to search for patterns and replace with different values.
Vim Modes
Learn about seven of Vim’s modes
Copy & Paste in Vim / Vi
Copy (Yank), Paste (Put) and Cut (Delete) in Vim
Undo & Redo in Vim / Vi
Keyboard shortcuts and summary of how Vim tracks changes
Show & Hide Line Numbers in Vim / Vi
Toggle absolute and relative line numbers
Select all in Vim / Vi
Select all and copy, paste, or delete the contents
Searching in Vim
Search forward, backward, case insensitive, and more
Go To End of File in Vim / Vi
Select and delete to the end of a file in Vim
How to delete lines in Vim / Vi
The best answer depends on which mode you use