VIM summary -- List of commands
List of commands
This is a list of commands that I often use. It's just a small fraction of the vim commands. But I'll add new things when I have time.
Please note that a command starting with a colon or a slash or a question mark must be ended by the Enter key -- that is not indicated in my list, while other command doesn't need the Enter key.
File and window commands
:e filename | | open a new file |
:e! filename | | open a new file without saving the current one |
:w filename | | write buffer to file |
:w! filename | | write buffer to an existing file |
:r filename | | read file to buffer |
:new | | split window and load an empty file |
:split | | split window |
:new filename | | open file in a sub window |
Ctrlww | | Jump to next window |
:n | | Edit the next file |
Moving by text objects
|
| |
h | | move the cursor one position left |
j | | move the cursor one position down |
k | | move the cursor one position up |
l | | move the cursor one position right |
w | | move cursor forward to first character of next word |
e | | move cursor forward to last character of next word |
b | | move cursor backward to first character of previous word |
W | | same as w; ignore punctuation |
E | | same as e; ignore punctuation |
B | | same as b; ignore punctuation |
) | | move forward to next sentence beginning |
( | | move backward to previous sentence beginning |
} | | move forward to next paragraph beginning |
{ | | move backward to previous paragraph beginning |
Move to absolute position in a line
0 | | move cursor to beginning of current line |
$ | | move cursor to end of current line |
^ | | move cursor to first non-space/tab in current line |
Move to absolute position in the file
G | | jump to the end of the file |
gg | | jump to the beginning of the file |
| | jump to the beginning of the file |
nG | | jump to nth line |
:n | | jump to nth line |
Move by screen
Ctrlf | | move cursor forward by one screen |
Ctrlb | | move cursor backward by one screen |
Move to absolute position on the screen
H | | move cursor to top line |
M | | move cursor to middle line |
L | | move cursor to last line |
Other
'' | | move cursor to previous position |
'x | | mover cursor to marker x, where x is a letter from a to z |
% | | move cursor to the match of a parethesis, bracket or brace |
SPACE | | move cursor one position right |
ENTER | | move cursor to beginning of next line |
Summary of inserting commands
|
| |
i | | change to insert mode; begin insertion at the cursor |
a | | change to insert mode; begin insertion after the cursor |
| | |
I | | change to insert mode; begin insertion at the beginning of the current line (=^i) |
A | | change to insert mode; begin insertion at the end of the current line (=$a) |
o | | change to insert mode; open a new line below the current line |
O | | change to insert mode; open a new line above the current line |
Summary of deleting commands
x | | delete one character at cursor |
X | | delete character in the left |
D | | delete from cursor to end of line |
dd | | delete the entire current line |
dmove | | delete from cursor to the location specified by the cursor motion command move. Eg: dw d2w dG dgg d0 d$ ... Try them |
Summary of copying commands
Y | | Copy current line to unnamed buffer |
yy | | Copy current line to unnamed buffer |
"cyy | | copy the current line to buffer named or numbered c |
nyy | | copy n lines below current line |
"cnyy | | copy n lines to buffer named or numbered c |
Summary of pasting commands
p | | put the contents of the unnamed buffer below the current line or after the cursor position |
P | | put the contents of the unnamed buffer above the current line or before the cursor position |
"cp | | put the contents of the buffer named or numbered c below the current line or after the cursor position c |
"cP | | put the contents of the buffer named or numbered c above the current line or below the cursor position c |
Summary of vim replacing commands
rx | | replace the character at cursor with the new character x |
R | | replacing by typing over (enter replace mode) |
s | | replace one character by insertion (enter insert mode) |
C | | replace from cursor to end of line (enter insert mode) |
cc | | replace entire current line (enter insert mode) |
S | | =cc |
cmove | | replace from cursor to move (a cursor-moving command) (enter insert mode) |
Search commands
/pattern | | search forward for a pattern |
?pattern | | search backward for a pattern |
n | | jump to the next occurrence of the last searched pattern |
N | | jump to the next occurrence of the last searched pattern in the opposite direction of the search |
* | | jump to the next occurrence of the word at the current cursor position |
# | | jump to the previous occurrence of the word at the current cursor position |
Inline character search
fc | | search for a character in the current line |
Fc | | search for a character in the current line in backward direction |
; | | repeat the last f or F search in the same direction |
, | | repeat the last f or F search in the opposite direction |
Substitute command esamples
:s/old/new/ | | substitute the first old in current line with new |
:s/old/new/g | | substitute all olds in current line with new |
:s/old/new/gc | | substitute all olds in current line with new, with your confirm |
:n1,n2s/old/new/g | | substitute all olds between the two lines with new |
:n1,$s/old/new/g | | substitute all olds from line n1 to the end with new |
:%s/old/new/g | | substitute all olds with new |
:%s/old/new/gc | | substitute all olds with new, with your confirm |
Miscellaneous commands
mc | | mark current line with an letter c |
'c | | move cursor to the line marked with the letter c |
qc...q | | record a sequence of key strokes to the register c |
@c | | play back the key strokes recorded in register c |
n@c | | play back the key strokes recorded in register c n times |
:rangeg/pattern/cmd | | execute the cmd for each line in range matching the pattern |
:rangev/pattern/cmd | | execute the cmd for each line in range not matching the pattern |
v | | enter visual mode |
V | | enter visual lines mode |
Ctrlv | | enter visual block mode |
:f | | display information of the file |
Ctrl-g | | =:f |
u | | undo the most recent change |
CtrlR | | redo the last undone change |
. | | repeat the most recent command that made a change. |
:!command | | execute a shell command |
:r!command | | insert the output of a shell command after the cursor |
:sh | | start a shell (type exit to return to vim) |
Cool commands
rENTER | | break a line |
J | | join the current line and the next line. |
~ | | toggle the case of the letter. |
ga | | show ASCII value of a character. |
:as | | show ASCII value of a character. |
% | | move cursor to match a parenthesis, bracket or brace |
xp | | exchanging two characters |
ddp | | exchanging two lines |
Labels: ASIC/IC Studybook
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home