zhuang@linux:~/reading/practical-vim/08-navigate-inside-files-with-motions/$ less
Navigate Inside Files with Motions
This post extracts some knowledge from Chapter 8 – Navigate Inside Files with Motions.
| Command | Move Cursor |
|---|---|
j | Down one real line |
gj | Down one display line |
k | Up one real line |
gk | Up one display line |
0 | To first character of real line |
g0 | To first character of display line |
^ | To first nonblank character of real line |
g^ | To first nonblank character of display line |
$ | To end of real line |
g$ | To end of display line |
| Command | Move Cursor |
|---|---|
w | Forward to start of next word |
b | Backward to start of current/previous word |
e | Forward to end of current/next word |
ge | Backward to end of previous word |
W B E gE for WORDS.
A word consists of a sequence of letters, digits, and underscores, or as a sequence of other nonblank characters separated with whitespace.
The definition of a WORD is simpler: it consists of a sequence of nonblank characters separated with whitespace.
Use WORD-wise motions if you want to move faster, and use word-wise motions if you want a more fine-grained traversal.
| Command | Effect |
|---|---|
f{char} | Forward to the next occurrence of {char} |
F{char} | Backward to the previous occurrence of {char} |
t{char} | Forward to the character before the next occurrence of {char} |
T{char} | Backward to the character after the previous occurrence of {char} |
; | Repeat the last character-search command |
, | Reverse the last character-search command |
use f and F in Normal mode, and t and T in Operator-Pending mode.
/pattern<CR>
| Text Object | Selection | Text Object | Selection |
|---|---|---|---|
a) or ab | A pair of (parentheses) | i) or ib | Inside of (parentheses) |
a} or aB | A pair of {braces} | i} or iB | Inside of {braces} |
a] | A pair of [brackets] | i] | Inside of [brackets] |
a> | A pair of <angle brackets> | i> | Inside of <angle brackets> |
a' | A pair of 'single quotes' | i' | Inside of 'single quotes' |
a" | A pair of "double quotes" | i" | Inside of "double quotes" |
a` | A pair of `backticks` | i` | Inside of `backticks` |
at | A pair of <xml>tags</xml> | it | Inside of <xml>tags</xml> |
很多内置插件都采用 package 机制管理,matchit 通常被放在 opt 目录下,因此默认不会自动加载,需要手动:
vim 
| Keystrokes | Current content | Keystrokes | Current content |
|---|---|---|---|
| iw | word | aw | word plus space(s) |
| iW | WORD | aW | WORD plus space(s) |
| is | sentence | as | sentence plus space(s) |
| ip | paragraph | ap | paragraph plus blank line(s) |
As a general rule, we could say that the d{motion} command tends to work well with aw, as, and ap, whereas the c{motion} command works better with iw and similar.
The m{a-zA-Z} command marks the current cursor location with the designated letter.
'{mark} moves to the line where a mark was set, positioning the cursor on the first non-whitespace cahracter.
`{mark} command moves the cursor to the exact position where a mark was set, restoring the line and the column at once.
Automatic Marks as follows:
| Keystrokes | Buffer Contents |
|---|---|
| ```` | Position before the last jump within current file |
`. | Location of last change |
`^ | Location of last insertion |
`[ | Start of last change or yank |
`] | End of last change or yank |
`< | Start of last visual selection |
`> | End of last visual selection |
zhuang@linux:~/reading/practical-vim/08-navigate-inside-files-with-motions/$ comments