Difference between revisions of "VI Editor Quick Reference"
Jump to navigation
Jump to search
m |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | ===Starting Vi=== | |
− | |||
− | Starting Vi | ||
* edit an empty buffer: vi | * edit an empty buffer: vi | ||
* edit a file: vi filename | * edit a file: vi filename | ||
− | Leaving Vi | + | ===Leaving Vi=== |
* write buffer to file: :w | * write buffer to file: :w | ||
* write buffer to file filename: :w filename | * write buffer to file filename: :w filename | ||
Line 13: | Line 11: | ||
* write changes and quit: ZZ | * write changes and quit: ZZ | ||
− | Special Notes | + | ===Special Notes=== |
* Use the escape key, <esc>, to leave insert mode or to cancel an incomplete command. | * Use the escape key, <esc>, to leave insert mode or to cancel an incomplete command. | ||
* If a command doesn't work, try hitting <esc> and entering the command again. | * If a command doesn't work, try hitting <esc> and entering the command again. | ||
− | Motion commands | + | ===Motion commands=== |
* move up one line: k | * move up one line: k | ||
* move down one line: j | * move down one line: j | ||
Line 42: | Line 40: | ||
All commands except M, nG, and :n can be preceeded by an integer to indicate the distance to move. | All commands except M, nG, and :n can be preceeded by an integer to indicate the distance to move. | ||
− | Text entering commands | + | ===Text entering commands=== |
* append text at end of line: A | * append text at end of line: A | ||
* append text after cursor: a | * append text after cursor: a | ||
Line 51: | Line 49: | ||
All commands must be terminated with an <esc> after the text has been entered. | All commands must be terminated with an <esc> after the text has been entered. | ||
− | Text deletion commands | + | ===Text deletion commands=== |
* delete character left of cursor: X | * delete character left of cursor: X | ||
* delete character under cursor: x | * delete character under cursor: x | ||
Line 65: | Line 63: | ||
All commands can be preceeded by an integer to indicate the number of characters, words, lines etc. to be deleted. | All commands can be preceeded by an integer to indicate the number of characters, words, lines etc. to be deleted. | ||
− | Text alteration commands | + | ===Text alteration commands=== |
* replace text: R | * replace text: R | ||
* replace character with c: rc | * replace character with c: rc | ||
Line 77: | Line 75: | ||
The commands R, cw, c) and c} must be terminated with an <esc> after the new text has been entered. All commands, except xp, u, and U can be preceded by an integer to indicate the amount of alteration to perform. | The commands R, cw, c) and c} must be terminated with an <esc> after the new text has been entered. All commands, except xp, u, and U can be preceded by an integer to indicate the amount of alteration to perform. | ||
− | Text moving commands | + | ===Text moving commands=== |
* yank a copy of the current line and place it in a buffer: yy | * yank a copy of the current line and place it in a buffer: yy | ||
* put the last item yanked or deleted before the cursor: P | * put the last item yanked or deleted before the cursor: P | ||
Line 86: | Line 84: | ||
The commands Y and "cY can be preceeded by and integer to indicate the number of lines to copy. | The commands Y and "cY can be preceeded by and integer to indicate the number of lines to copy. | ||
− | Search Commands | + | ===Search Commands=== |
* search forward for pattern: :/pattern/ | * search forward for pattern: :/pattern/ | ||
* search forward for pattern: /pattern/ | * search forward for pattern: /pattern/ | ||
Line 96: | Line 94: | ||
* repeat the last search in opposite direction: N | * repeat the last search in opposite direction: N | ||
− | Global parameter | + | ===Global parameter=== |
* substitute pat2 for pat1: :g/pat1/s/pat1/pat2 | * substitute pat2 for pat1: :g/pat1/s/pat1/pat2 | ||
* delete all occurrences of pat1: :g/pat1/d | * delete all occurrences of pat1: :g/pat1/d | ||
* print all occurrences of pat1: :g/pat1/p | * print all occurrences of pat1: :g/pat1/p | ||
− | Addresses | + | ===Addresses=== |
* the nth line: n | * the nth line: n | ||
* lines n through k: n,k | * lines n through k: n,k | ||
Line 110: | Line 108: | ||
* the last n+1 lines: $-n,$ | * the last n+1 lines: $-n,$ | ||
− | Miscellaneous | + | ===Miscellaneous=== |
* read file filename into the buffer after the current line: :r filename | * read file filename into the buffer after the current line: :r filename | ||
* read the output of command cmd into: the buffer after the current line: :r !cmd | * read the output of command cmd into: the buffer after the current line: :r !cmd |
Latest revision as of 14:16, 10 September 2006
Contents
Starting Vi
- edit an empty buffer: vi
- edit a file: vi filename
Leaving Vi
- write buffer to file: :w
- write buffer to file filename: :w filename
- quit: :q
- quit discarding changes: :q!
- write changes and quit: :wq
- write changes and quit: ZZ
Special Notes
- Use the escape key, <esc>, to leave insert mode or to cancel an incomplete command.
- If a command doesn't work, try hitting <esc> and entering the command again.
Motion commands
- move up one line: k
- move down one line: j
- move left one character: h
- move right one character: l
- scroll up one line: <ctrl>y
- scroll down one line: <ctrl>e
- scroll up (default is a half page): <ctrl>u
- scroll down (default is a half page): <ctrl>d
- show next page page: <ctrl>f
- show previous page page: <ctrl>b
- move to beginning of next line: +
- move to beginning of previous line: -
- move to beginning of first screen line: H
- move to middle line of screen: M
- move to last line of screen: L
- move to the nth line: nG
- move to the nth line: :n
- move to the next occurrence of c on the current line: fc
- move to the character in front of the next occurrence of c on the current line: tc
- move forward to the next word: w
- move forward to the end of the next word: e
- move backward to the previous word: b
All commands except M, nG, and :n can be preceeded by an integer to indicate the distance to move.
Text entering commands
- append text at end of line: A
- append text after cursor: a
- insert text at beginning of line: I
- insert text before cursor: i
- open a new line above cursor: O
- open a new line below cursor: o
All commands must be terminated with an <esc> after the text has been entered.
Text deletion commands
- delete character left of cursor: X
- delete character under cursor: x
- delete rest of word: dw
- delete rest of sentence: d)
- delete rest of paragraph: d}
- delete to beginning of current line: d^
- delete to end of current line: d$
- delete to end of current line: D
- delete line containing cursor: dd
- delete the current line upto and including c: dfc
- delete the current line upto c: dtc
All commands can be preceeded by an integer to indicate the number of characters, words, lines etc. to be deleted.
Text alteration commands
- replace text: R
- replace character with c: rc
- transpose two characters: xp
- join the next line to the end of the current line: J
- undo last change: u
- undo last change to current line: U
- change rest of word: cw
- change rest of sentence: c)
- change rest of paragraph: c}
The commands R, cw, c) and c} must be terminated with an <esc> after the new text has been entered. All commands, except xp, u, and U can be preceded by an integer to indicate the amount of alteration to perform.
Text moving commands
- yank a copy of the current line and place it in a buffer: yy
- put the last item yanked or deleted before the cursor: P
- put the last item yanked or deleted after the cursor: p
- yank a copy of the current line and place it in buffer c: "cY
- put contents of buffer c on a new line above the cursor: "cP
- put contents of buffer c on a new line below the cursor: "cp
The commands Y and "cY can be preceeded by and integer to indicate the number of lines to copy.
Search Commands
- search forward for pattern: :/pattern/
- search forward for pattern: /pattern/
- search backward for pattern: :?pattern?
- search backward for pattern: ?pattern?
- delete the next line containing pat1: :/pat1/d
- substitute the next occurance of pat1 with pat2: :/pat1/s/pat1/pat2
- repeat the last search: n
- repeat the last search in opposite direction: N
Global parameter
- substitute pat2 for pat1: :g/pat1/s/pat1/pat2
- delete all occurrences of pat1: :g/pat1/d
- print all occurrences of pat1: :g/pat1/p
Addresses
- the nth line: n
- lines n through k: n,k
- the current line: .
- the last line: $
- n lines after the current line: +n
- n lines before the current line: -n
- the last n+1 lines: $-n,$
Miscellaneous
- read file filename into the buffer after the current line: :r filename
- read the output of command cmd into: the buffer after the current line: :r !cmd
- write the buffer to file filename replacing its previous contents: :w! Filename
- write the buffer to the end of file filename: :w >> filename
- turn on line numbering: :set number
- turn off line numbering: :set nonumber
- turn on auto indenting: :set autoindent
- turn on auto indenting: :set ai
- turn off auto indenting: :set noautoindent
- turn off auto indenting: :set noai