H | J | K | L |
Your index finger goes on the H, the middle finger on the J, the ring finger on the K, and the pinkie on the L. h goes left, j goes down, k goes up, and l goes to the right (the table below does list them).
Notice that on a keyboard, the letters are shown as capitals. The commands are lower case. It is very important to remember that vi is case sensitive. For instance, an example above lists J for join. This is a different command than j, which moves the cursor down a line.
You can also use the enter key to move down, the space bar to move right, the back-space to move left, and - to move up.
What is the difference between these two sets of commands? Specifically, how do j and k differ from enter and -? Try them and see.
You can press CTRL-B to scroll back half a page, press CTRL-U to scroll up a page, press CTRL-D to scroll down half a page, and press CTRL-F to scroll forward a page. CTRL-E will scroll down a single line.
Note that the scrolling commands are not meant to move the cursor. vi will keep the cursor on the current visible test, but it may not be where you might expect it. Scrolling is meant to affect the text that you can see within your vi window.
Command | Description |
h | moves the cursor to the left. |
j | moves the cursor down. |
k | moves the cursor up. |
l | moves the cursor to the right. |
Enter | moves the cursor down. |
- | moves the cursor up. |
space | moves the cursor to the right. |
back-space | moves the cursor to the left. |
w | moves the cursor to the next word. |
b | moves the cursor back to the previous. |
e | moves the cursor to the end of the current word. |
G | goes to the last line in the file. |
1G | goes to the first line in the file. You can use any line number, not just a 1. |
$ | goes to the end of the current line. |
fe | finds the next e on the current line. You can specify any letter, not just an e. |
Fe | finds the previous e on the current line. You can specify any letter, not just an e. |
/any string | finds the specified text after the cursor and moves the cursor there. Will go forward to different lines. You must press Enter to have the search execute. |
?any string | finds the specified text before the cursor and moves the cursor there. Will go backwards to different lines. You must press Enter to have the search execute. |
% | moves the cursor to the matching parenthesis or open/close curly brace. This is very useful for programming, especially C and C++ because these languages use { and }. |
CTRL-B | scrolls back half a page of text. |
CTRL-U | scrolls up a page of text. |
CTRL-D | scrolls down half a page of text. |
CTRL-F | scrolls forward a page of text. |
CTRL-E | scrolls down by a single line. |