Anda di halaman 1dari 1

vi CHEAT SHEET

General Edit
Vi begins in command mode, where the cursor movement and Prefix commands below with single lowercase letter to use
text deletion and pasting occur. Insertion mode begins upon specific buffer instead of general clipboard.
entering an insertion or change command. [ESC] returns to
command mode. Change “c”+<Move> commands delete and enter insert mode.

Most commands execute as soon as you type them, c<Move> delete text specified by Move, enter insert mode
"colon" commands execute when you press the return key. C change to end of line (same as c$)
cc change the whole line
Prefix most commands with a number to repeat it. S change the whole line (same as cc)
s delete character at cursor and subsitute text
Quit Delete “d”+<Move> commands delete text specified by Move.
:q quit (fails if anything has changed)
:q! quit and throw away changes d<Move> delete text specified by Move
:w write (save) the file x delete character at cursor (Del)
:w <file> save as X delete character before cursor (Backspace)
:wq write (save) and quit D delete to end of line
ZZ write (save) and quit dd delete the whole line
:d delete the whole line
Scroll J join line below to this (change LF to space)

C-d scroll down half screen Yank “y”+<Move> commands copy text specified by Move
C-u scroll up half screen
C-f page forward (down) y<Move> yank text specified by Move
C-b page backward (up) yy yank the whole line
z. scroll window, cursor in the middle :y yank the whole line

Put commands paste the clipboard.


Move
p put (paste) the clipboard AFTER cursor
Arrow and navigation keys can be used as well.
P put (paste) the clipboard AT cursor
h left or left arrow
j down or down arrow Visual
k up or up arrow Start a visual selection, then type a command.
l right or right arrow
v<Move> start visual mode
w next word V<Move> start visual mode, whole lines only
W next word - blank delimited C-v<Move> start visual block mode
e end of word o move to opposite end of marked area
E end of word - blank delimited O move to other corner of block horizontally
b previous word Esc exit visual mode
B previous word - blank delimited

0 (zero) start of line Search


^ first non-blank character of line General form [/?]pattern[/?]<offset><LF>
$ end of line
/pattern search forward for pattern
G go to last line ?pattern?-2 search backward for pattern, go to 2 nd line above
1G go to 1st line //e repeat last search pattern, go to end of match
H top of screen / repeat last search pattern with last offset
M middle of screen n repeat search in same direction
L bottom of screen N repeat search in opposite direction

% associated () [] {} Replace
General form :[range]s/pattern/string/[flags]
Windows
:e <file> Edit a file in a new buffer :%s/old/new/ replace first in each line of file
:sp <file> Open a file in a new buffer and split window :%s/old/new/gc replace all with confirmations
:bn go to next buffer in same window :.,$s/foo/bar/gi replace all downwards, ignore case
:bp go to previous buffer in same window :.-10,.+10s/foo/bar/g replace all within 10 lines distance
:bd delete a buffer (close a file) & repeat last replace command without flags
C-w s Split windows :&& repeat last replace command with flags
C-w v Split windows vertically
C-w w switch between windows Regexp
C-w<Move> switch to window in direction of Move * zero or more
C-w q Quit a window \? zero or one
\+ one or more
Insert
vi will remain in insert- or replace mode until pressing ESC. Other
i start insert mode at cursor u undo
I insert at the beginning of the line . redo
a append after the cursor ~ toggle case
A append at the end of the line g~<Move> toggle case of characters specified by Move
o open (append) blank line below (no LF needed)
O open blank line above current line > indent
< unindent
r replace single character, stay in command mode :[range]>[n] indent n lines in range
R start replacing many characters at cursor :[range]<[n] unindent n lines in range

Anda mungkin juga menyukai