Being able to quickly and accurately move to where you need to be in Vim is an important skill, and one that only takes a little practice before you’ll be zooming to right where you need to be! In this hands-on lab, we will start with the basics of moving around in a buffer or file’s contents, getting to top/bottom, directly to a given line, or move around in large movements such as by screen or buffer. We’ll then move around by paragraph, on a line, and even down to moving around word by word, both forward and backward for all movements.
Successfully complete this lab by achieving the following learning objectives:
- Move Around in Vim, Change the Cursor Line Positioning, and Navigate to the Buffer Boundaries
Open the Vim editor:
Create a working file:
When the file is written to disk, quit Help:
~/quotesdemo.txtfile in a buffer:
Navigate to the top of the file:
Navigate to the end of the file to see how many lines long it is:
Note: Pressing Ctrl+G will also display the number of lines in a buffer/file.
Navigate to line 100 of the file:
Noting the percentage shown on the far lower right of the screen, navigate to 50% of the way down the file:
To see if the top line of the screen is the start of a paragraph, press
kto move to the top line and move the display up one line.
Note: If the cursor won’t go to the top of the screen, use the following to turn OFF the
Reposition your cursor to the middle line of the screen by pressing
M, then to the bottom line of the screen with
Navigate to line 17:
O(upper-case "o") to open a new line above the one that begins:
Coming with a very GUI mindset...
While in Insert Mode, try the various navigation commands you have tried so far, then use the dedicated PgUp, PgDn, Home, End and cursor keys, which is all Insert Mode really allows for navigation.
Quit the demonstration file without saving changes:
- Affect Line Display, Show the Control Characters in Your Files, Navigate on Lines and by Words and Characters
Edit the demonstration file you created in Task 1:
Navigate to the top of the file:
Turn on the line numbers option:
Navigate to the first line of the fourth paragraph:
Your cursor should be on the first character of the line that begins:
Vim is so much better than vi...
Now move your cursor to the end of the line by pressing the
Note: Normally the end of a line and the end of a paragraph are the same thing, as a paragraph usually is a sentence or more ending in a Line Feed.
Note that you are not going to the closing parantheses following the word
Australia, as you would expect to. Look at the line numbers for a clue.
Set the displaying of un-printable characters on the screen:
Note that the
LF(Line Feed) character is at the end of each of the lines, indicating the use of a manual
ENTERto set the length of the line. This and line numbers tell the whole story.
Place your cursor on the top line of the paragraph that begins with:
Coming with a very GUI mindset....
Turn the multiple physical lines in the paragraph into a proper paragraph by pressing the
Jcharacter until there are no remaining
$characters in between
Now use the
$character to go to the end of the "line" you have just created out of five individual lines, then press the
^character to go to the beginning of the new paragraph/line.
wcharacter to move forward through the paragraph for 10 words, noticing how it treats punctuation as a word. Then use
5wto move forward five words at a time.
Navigate backwards to the beginning of the paragraph using
B, noticing how it treats the punctuation.
Look up why this happens:
Make sure to read the definitions of what a
WORDare and the difference. Also note similar information about
Position your cursor at the beginning of the paragraph that starts with
Coming with a very GUI....and then use
eto move to the end of the word, then several more, until you reach punctuation, noting where it stops, then use
^to then repeat those steps with
E, noting the (subtle) difference that makes.
Return to the top of the file:
Quit and don’t save the demonstration file: