vi筆記3——vi之快速移動
VI快速移動主要包含以下内容:
^F --Scroll forward one screen.
^B --Scroll backward one screen.
^D --Scroll forward half screen (down).
^U --Scroll backward half screen (up).
^E --scroll the screen up one line
^Y --scroll the screen down one line (^Y).
(In this list of commands, the ^ symbol represents the CTRL key. So ^F means to hold down the CTRL key and press the f key simultaneously.)
^L --Redrawing the Screen,When system messages appear on your screen, you need to redisplay, or redraw, the screen.
Movement Within a Screen
H --Move to home—the top line on screen.
M --Move to middle line on screen.
L --Move to last line on screen.
nH --Move to n lines below top line.
nL --Move to n lines above last line.
Movement by Line
ENTER --Move to first character of next line.
+ --Move to first character of next line.
- --Move to first character of previous line.
Home -- Move to first character of current line.
End -- Move to first character of current line.
Movement on the current line
Don’t 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
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.
Movement by Text Blocks
You have already learned to move forward and backward by word (w, W, b or B).
e --Move to end of word.
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.(如果檔案隻有一節,就跳到檔案最後一行)
Movement by Searches
?searchContent -- search backward,
/searchContent -- search forward,
n --Repeat search in same direction.(當使用/ 或者?後使用n可以依次跳轉到相應的查詢目标上面去)
N --Repeat search in opposite direction.
/ ENTER --Repeat search forward.equal to /
? ENTER --Repeat search backward.equal to ?
Sometimes you want to find a word only if it is further ahead; you don’t want the search to wrap around earlier in the file. vi has an option, wrapscan, that controls whether searches wrap. You can disable wrapping like this:
:set nowrapscan
When nowrapscan is set and a forward search fails, the status line displays the message:Address search hit BOTTOM without matching pattern
When nowrapscan is set and a backward search fails, the message displays “TOP”instead of “BOTTOM.”
Current Line Searches
fx --Find (move cursor to) next occurrence of x in the line, where x stands for any
character.
Fx --Find (move cursor to) previous occurrence of x in the line.
tx --Find (move cursor to) character before next occurrence of x in the line.
Tx --Find (move cursor to) character after previous occurrence of x in the line.
; --Repeat previous find command in same direction.
, --Repeat previous find command in opposite direction.
dfx --deletes up to and including the named character x.
yfx --yanks up to and including the named character x.
^G --顯示目前行數,總行數,目前百分比;但是本人使用windows的vim和ubuntu1604的vim時候隻顯示了總行數和百分比
nGG --move to number n
G --move to the last number of the file
'' --兩個單引号,傳回到最後一次使用G的位置
Examples
Remember that you can combine numbers with movement. For example, 3) moves ahead three sentences. Also remember that you can edit using movement commands: d) deletes to the end of the current sentence, 2y} copies (yanks) two paragraphs ahead.
Review of vi Motion Commands
Table 3-1. Movement commands
Movement Command
Scroll forward one Screen ^F
Scroll backward one screen ^B
Scroll forward half screen ^D
Scroll backward half screen ^U
Scroll forward one line ^E
Scroll backward one line ^Y
Move current line to top of screen and scroll z ENTER
Move current line to center of screen and scroll z.
Move current line to bottom of screen and scroll zRedraw the screen ^L
Move to home—the top line of screen H
Move to middle line of screen M
Move to bottom line of Screen L
Move to first character of next line ENTER
Move to first character of next line +
Move to first character of previous line -
Move to first nonblank character of current line ^
Move to column n of current line n|
Move to end of word e
Move to end of word (ignore punctuation) E
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 ]]
Search forward for pattern /pattern
Search backward for pattern ?pattern
Repeat last search n
Repeat last search in opposite direction N
Repeat last search forward /
Repeat last search backward ?
Move to next occurrence of x in current line fx
Move to previous occurrence of x in current line Fx
Move to just before next occurrence of x in current line tx
Move to just after previous occurrence of x in current line Tx
Repeat previous find command in same direction ;
Repeat previous find command in opposite direction ,
Go to given line n nG
Go to end of file G
Return to previous mark or context ``
Return to beginning of line containing previous mark ''
Show current line (not a movement command) ^G