Some vi commands | printable version (.doc) |
(some of them may not work in certain kinds of vi versions) |
Mixed | Moving | ||
:help | CTRL-] ... get into item, CTRL-T ... leave item, :q<Enter> ... quit help | <n> h j k l | left, down, up, right (n-times, n=1 if omitted) |
:map | look at macro definitions | 0 | $ | move to beginning | end of line |
:map ^Z ddOHallo!^[0j | means map the key ^Z to following macro: delete line (dd), create new line above cursor (O), insert "Hallo!", stop insert mode (ESC=^[), go to beginning of line (0), goto next line (j) | <n>| | move to column n, if n omitted move to column 1 ("|" means pipe) |
:unmap <key> | kills macro binding | <n>e | n words forward (end of word) |
:set ic | ignore case (for searching and replacing) | <n>w | n words forward (beginning of word), Shift -<right arrow> |
:set nu | display line numbers | <n>b | n words backward (beginning of word), Shift-<left arrow> |
u | U | undo last change | recover last line | <n>g | go n lines down |
. (dot) | repeat last command | <n>G | goto line n, if n omitted goto end of file |
^G | show filename, current line number, total line numbers, ... | ||
^V | quote next char, eg. ^V^M is newline | ||
Paging | Searching | ||
^F | page forward | /<pattern><RET> | search pattern forward |
^B | page backward | ?<pattern><RET> | search pattern backward |
^D | half page forward | n | N | find next | previous match |
^U | half page backward | ||
^Y | scroll window up one line | ||
^E | scroll window down one line | ||
Inserting | Deleting | ||
i | insert text under the cursor | x | delete character under the cursor |
o | O | create a new line under | above the cursor and insert text | X | delete previous character |
a | insert after cursor | de | delete the remaining word from cursor-position (excl following space) |
A | insert at end of line | dw | delete the remaining word from cursor-position (incl following space) |
J | concatenate this and next line | d$ | delete to end of line |
p | P | paste after | before cursor | ||
dG | delete to end of file | ||
[n]dd | delete the entire [n] line(s) | ||
Copying | Substitute | ||
<reg> is a single letter register name: "a - "z ... replace reg contents, "A - "Z ... append to reg content |
r | R | replace char under cursor | replace until ESC | |
["<reg>][<n>]yy | copy n lines into register reg, n=1 if omitted | s | character under the cursor is substituted by a string |
["<reg>]1y6<RET> | copy 1 x 6 characters into register reg (chars right from cursor) | cw | the remaining word from cursor-pos is substituted by a string |
["<reg>]6y1<RET> | copy 6 x 1 characters into register reg (chars right from cursor) | cc | the entire line is substituted by a string |
["<reg>]p | insert register reg (below cursorposition if reg contains lines, after cursorposition if reg contains characters) |
:[rng]s/abc/xyz/[c g i] | substitute "abc" by "xyz" : c: confirm, g: whole line, i: case insensitive rng: range, example 5,7 : line 5 to 7 = 3 lines, . current, $ last, % all (=1,$) |
:reg | display contents of registers | ||
Leaving | Files | ||
:q | no changes were made | :r[ead] <filename> | insert file at cursor position |
:q! | ignore changes | :e[dit][!] <filename> | [force (=ignore changes)] edit filename |
:wq | write file and quit | :w[rite][ <filename>] | save file, another filename can be chosen |
Windows | |||
^Ws | split horizontally (same file) | ||
^Wv | split vertically (same file) | ||
^Wn | split horizontally (new file) | ||
^Wc | close current window | ||
^Wq | quit current window | ||
^Wj | select window above | ||
^Wk | select window below | ||
<n>^W+, <n>^W- | resize current window |