Open phish108 opened 2 years ago
vi distinguishes between edit mode and command mode. When starting vi it will launch into command mode.
ESC
CONTROL+g
u
.
:w
ZZ
:x
:q
:qa
:q!
:qa!
i
a
o
O
r
s
cc
C
dd
D
yy
Y
p
P
Delete multiple lines by adding the number of lines before dd. E.g., 6dd deletes 6 lines.
6dd
Search commands do not affect undo and repeat commands.
/search-pattern
?search-pattern
n
N
Search and replace commands do affect undo and repeat commands.
:s/search-pattern/replace-string
:%s/search-pattern/replace-string
:.,$s/search-pattern/replace-string
:3,9s/search-pattern/replace-string
:number
number
:10
10
^
$
e
w
b
E
B
vi distinguishes between edit mode and command mode. When starting vi it will launch into command mode.
ESC
- leaves edit mode and enters command mode (multiple pressing does not harm)CONTROL+g
- shows document status and current position of the cursor.Undo and Redo
u
- undo the last command.
- repeat the last commandWriting and quitting
:w
- write all changes into the corresponding fileZZ
- write all changes and quit vi:x
- same asZZ
:q
- quit vi without saving:qa
- quit vi for all buffers (sometimes:q
does not work):q!
- quit and drop any changes (or:qa!
if:q!
refuses to work)Editing
i
- enter edit mode before the current cursor position (insert)a
- enter edit mode after the current cursor position (append)o
- create a new line below the current line and enter edit modeO
- create a new line above the current line and enter edit moder
- exchanges a single character at the current cursor positions
- same asr
but stays in edit modecc
- delete the current line and enter edit modeC
- delete everything from the current position to the end of the line and enter edit modeDeleting and Copy and Paste
dd
- delete the current line and places the content into the paste bufferD
- delete the rest of the line from the current position and places the content into the paste bufferyy
- places the current line into the past buffer without deletingY
- and places the rest of the line from the current position into the paste bufferp
- insert the paste buffer after the current position. If it is a line paste below the current lineP
- same asp
but before the current position.Search
/search-pattern
- search for the search pattern from the current position towards the end of the file?search-pattern
- search for the search pattern from the current position towards the beginnen of the file (reverse search)n
- move to the next match (in the direction of search)N
- move to the previous match (in the direction of search)Search and replace
:s/search-pattern/replace-string
- replace the search-pattern with the replace-string in the current line:%s/search-pattern/replace-string
- replace the search-pattern with the replace-string in the entire file:.,$s/search-pattern/replace-string
- replace the search-pattern with the replace-string from the current position to the end of the file:3,9s/search-pattern/replace-string
- replace the search-pattern with the replace-string between the given line numbersMoving the cursor
:number
- move the cursor to the line number given bynumber
. E.g.:10
moves the cursor to line number10
.^
- move to the beginning of the line$
- move to the end of the linee
- move the cursor to the next word boundary (marked by the same character type of the current position)w
- same ase
but moves after the next word boundaryb
- move the cursor to the previous word boundaryE
- move the cursor before the next whitespaceB
- move the cursor after the previous whitespace