Vim |
Normal Mode Delegate
(switch to Normal by press `<Esc>`)
Insert Mode
Delete
T13: delete in insert mode
`<C-h>`: Delete back one character
<`C-w`>: Delete back one word
<`C-u`>: Delete back to start of line
Paste
T15: paste from a register in insert mode
`yt,` + `<C-r>`0: yank until ',' and paste from register 0
Mode Switch
T14: get back to normal mode
`<Esc>`: too far for finger to reach
`<C-[>`: easier than `<Esc>`
Calculator
T16: do calculation in place
`<C-r>=3*6`
Replace Mode
(identical to insert mode
except line length not change)
T19: overwrite existing text with replace mode
`R{some text}`
Normal Mode
(Action + Motion), c2w
Find
In current line
`f{char}`: move cursor to next {char}
`;`: next {char}
`,`: previous {char}
Upper/Lower Case
`gu`, `gU`, `g~`
`v`: Visual Mode
(Motion(start, end)+Action)
`<S-v> c`
Character-wise `v`
Line-wise `<S-v>`
T22: repeat line-wise visual commands
`<S-v>j` + `>` + `.`
Block-wise `<C-v>`
T24: edit table in block-wise mode
`<C-v>3j` + `x` + `....` +
`gv` + `r|` +
`yyp` + `<S-v>` + `r-`
T25: change columns of text
`<C-v>3j` + `e` + `c` + `{target text}`
T26: append after ragged block
`<C-v>3j$` + `A` + `;` + `<Esc>`
Other
Repeate last range `gv`
Go to other end of highlighted text `o`
T23: Prefer visual mode operator over
visual mode command
Command-Line Mode
`:`: Ex command
(used for long range while
normal node for local range,
see T29)
T28: execute a command on
multiple consecutive lines
Use Line numbers as Address
`:1` + `p`
Specify a range of lines by address
`:2,5p`
`:.,$p` // . current line
Specify a range of lines by visual selection
`2G` + `<S-v>G` + `:` +
`s/vim/emacs`
Specify a Range of lines by Patterns
:/<html>/, /<\/html>p
Specify a Range of lines by Offset
:/<html>/+1, /<\/html>-1p
T29: copy `:t`, or move `:m` lines
Copy lines with `:t` command
`:6copy.` // copy line 6 to current line
`:6t.` // `t` is the same as `copy`
// this is more convenient than normal mode `6G` + `yy` + `1G` + `p`
Move lines with `:m` command
`<S-v>3j` + `:m$` // select 3 line and move the end
T30: run normal mode commands
across a range
`:%normal A;` // add ; to each line
`:%normal i//` // comment each line
T31: repeat the last ex command
`:@:` // different than `.` in normal mode
T32: auto-complete ex command
`:col<C-d>`
T33: insert current word at
command prompt
`:%//<C-r><C-w>/g`
T34: recall commands from history
`:<UP>` or `:<DOWN>` or `:help <UP>`
T35: run commands in the shell
`:!ls` run ls bash command in vim
`!` is named "bang"
Note `:!ls` diffs `:ls`, which
run vim built-in ls command to display buffer list
`:shell` enter shell from vim
`:exit` exit shell back to vim
use content of buffer as stdin or stdout
`/`: search pattern
an expression
Files
File (in disk)
`:write`, `:update`, `:saveas`
Buffer (in-memory mapping of files in disk)
Consistent with file when file first loaded to buffer;
when buffer is changed the two diverge;
When buffer is saved to file, the two are consistent.
T37: track open files with buffer list
`:ls`
`:[b`, `:]b`, `:[B`, `:]B`
`:N1bd`, `:N1,N2bd`
T38: group buffers into a collection