cursor remains at the same point in the line as when the command was issued.
Repositioning the Screen with z
If you want to scroll the screen up or down, but you want the cursor to remain
z on the line where you left it, use the z command.
z ENTER
Move current line to top of screen and scroll.
z.
Move current line to center of screen and scroll.
z-
Move current line to bottom of screen and scroll.
With the z command, using a numeric prefix as a multiplier makes no sense. (After all,
you would need to reposition the cursor to the top of the screen only once. Repeating
the same z command wouldnt move anything.) Instead, z understands a numeric prefix
as a line number that it will use in place of the current line. For example, z ENTER
moves the current line to the top of the screen, but 200z ENTER moves line 200 to the
top of the screen.
36 | Chapter 3:Moving Around in a Hurry
Redrawing the Screen
Sometimes while youre editing, messages from your computer system
CTRL
L will display on your screen. These messages dont become part of your
editing buffer, but they do interfere with your work. When system messages appear on
your screen, you need to redisplay, or redraw, the screen.
Whenever you scroll, you redraw part of (or all of) the screen, so you can always get
rid of unwanted messages by scrolling them off the screen and then returning to your
previous position. But you can also redraw the screen without scrolling, by typing
CTRL-L .
Movement Within a Screen
You can also keep your current screen, or view of the file, and move around within
H the screen using:
H
Move to homethe top line on screen.
M
Move to middle line on screen.
L
Move to last line on screen.
n H
Move to n lines below top line.
n L
Move to n lines above last line.
H moves the cursor from anywhere on the screen to the first, or home, line. M moves
to the middle line, L to the last. To move to the line below the first line, use 2H.
Keystrokes
Results
L
With a screen editor you can
scroll the page, move the cursor,
delete lines, insert characters, and more,
while seeing the results of your
edits as you make them.
Screen editors are very popular,
since they allow you to make changes
as you read through a file.
Move to the last line of the screen with the L command.
2H
With a screen editor you can
scroll the page, move the cursor,
delete lines, insert characters, and more,
while seeing the results of your
edits as you make them.
Screen editors are very popular,
since they allow you to make changes
as you read through a file.
Movement by Screens | 37
Keystrokes
Results
Move to the second line of the screen with the 2H command. (H alone moves to the top line of
the screen.)
Movement by Line
Within the current screen there are also commands to move by line.
Youve already seen j and k. You can also use:
ENTER
Move to first character of next line.
+
Move to first character of next line.
-
Move to first character of previous line.
These three commands move down or up to the first character of the line, ignoring any
spaces or tabs. j and k, by contrast, move the cursor down or up to the first position
of a line, even if that position is blank (and assuming that the cursor started at the first
position).
Movement on the current line
Dont forget that h and l move the cursor to the left and right, and that 0 (zero) and $
move the cursor to the beginning or end of the line. You can also use:
^
Move to first nonblank character of current line.
n |
Move to column n of current line.
As with the line movement commands shown earlier, ^ moves to the first character of
the line, ignoring any spaces or tabs. 0, by contrast, moves to the first position of the
line, even if that position is blank.
Movement by Text Blocks
Another way that you can think of moving through a vi file is by text blocks
e words, sentences, paragraphs, or sections.
You have already learned to move forward and backward by word (w, W, b or B). In
addition, you can use these commands:
e
Move to end of word.
38 | Chapter 3:Moving Around in a Hurry
E
Move to end of word (ignore punctuation).
(
Move to beginning of current sentence.
)
Move to beginning of next sentence.
{
Move to beginning of current paragraph.
}
Move to beginning of next paragraph.
[[
Move to beginning of current section.
]]
Move to beginning of next section.
To find the end of a sentence, vi looks for one of these punctuation marks: ?, ., or !.
vi locates the end of a
sentence when the punctuation is followed by at least two spaces
or when it appears as the last nonblank character on a line. If you have left only a single
space following a period, or if the sentence ends with a quotation mark, vi wont rec-
ognize the sentence.
A paragraph is defined as text up to the next blank line, or up to one of the default
paragraph macros (.IP, .PP, .LP, or .QP) from the troff MS macro package. Similarly,
a section is defined as text up to the next default section macro (.NH, .SH, .H 1,