Posted on — Jun 22, 2022
— Last Modified on — Jun 22, 2022
Vim Commands
Too Many Vim Commands
Getting back into Vim again and decided this time to take it slower and get the basics well in place before I try and incorporate too many commands. It’s the same mentality I’m bringing to my Python journey and will reapply to C#. The notes below are a mix of my obsidian notes from when I started using Vim in April of 2021 and resources I’ve used to better understand the commands this time round.
Phase One Commands
There were too many commands to get stated, so following the advise of The Primeagen Youtube Channel, I’m focusing for my first phase on the following commands. w, b, h, j, k, l, y, p, d, v, V, u, :w and :q.
Phase One Commands Explained
command
explanation
w
move forward one word
b
backwards one word
h, j, k, l
move left, down, up, right
y
yank
p
paste/put
d
delete
v
enter visual mode
V
enter line select visual mode
u
undo
:w
write file/save
:q
quit
Phase Two Commands
The goals is to feel comfortable with the phase one commands before moving on. Phase two commands are o, O, P, a, A, I, /, n, N, *, $.
Phase Two Commands Explained
command
result
o
open a new line and insert
O
open a new line above and insert
p
puts the yanked on the next line
P
puts the yanked on the previous line
i
insert before the cursor
I
insert at the beginning of the line
a
insert after the cursor (append)
A
insert at the end of the line (Append)
/
find
n
go to next search result
N
go to previous search result
*
go to next search result
$
go to previous search result
Phase Three Commands
Phase two commands are f, t, F, T, ;, ,, x, c, D, C, S..
Phase Three Commands Explained
command
result
f{character}
(find) next {character}
F{character}
(find) previous {character}
t{character}
until next character
T{character}
until previous character
;,
move to the next or previous result
x
delete
c
cut
C
cut to the end of the line
D
delete rest of the line
S
delete the rest of the line and
enter insert mode, properly indented
Phase Four Commands
Phase two commands are g, gg, :line number, G, gi, 18j, {, }, %, di{, yi{, cip, da[
Phase Four Commands Explained
command
result
g
go to last line of the file
gg
go to first line of file
gi
go to last insert change point and insert
G100
go to line number 100
:100
go to line number 100
dd
delete line
D
delete from cursor to end of line
dd
delete line
D
delete from cursor to line end
dw
delete word
d2W
delete two words
dt;
delete until ;
d/hell
delete until hell*
command
result
cw
change word
ci
change inner
ca
change around/append
ci
change inside quotes from line beginning
command
result
y{motion}
yank in a direction
yaw
yanks a word
yas
yanks a sentence
yap
yanks a paragraph
command
explanation
e
end of word
ge
go to the end of the previous word
gE
go to the end of the previous WORD
%
find matching
0
move to the fist character of a line
$
move to the end of the line
g_
move to the non-blank character at the end of a line
{
jump up one paragraph
}
jump down one paragraph
CTRL+D
Jump down one page
CTRL+U
jump up one page
So far so good.
Search and replace
:#,#s/older/new/g where #,# are the line numbers of the range of lines where the substitution is to be done.
:%s/older/new/g to change every occurrence in the whole file.
:%s/older/new/gc to find every occurrence in the whole file,
% typing when on a bracket takes you to the matching bracket.
Below are my scattered notes from obsidian, as I progress through the newer commands, I’ll add them here. For me at the moment it’s about practicing phase one. Once I move onto phase two I’ll add phase three etc. Why? Because it’ll be great practice using those commands when editing this post.
// d + i=> wdtSpolite<ESC>fcdsipolite<ESPACE><ESC>
// c => wctSpolite<ESC>fccwpolitely<ESPACE><ESC>
constcourteousSalute=Icourteouslysaluteyougoodperson.";
well that example was nothing! Wait till you see what’s coming.
Write, Quit, Open
EX commands start with a :
:write saves the file
:quit closes the file if there are no changes
:edit creates or opens a new or existing file
Visual Mode
command
explanation
v
for character-wise visual mode
V
for line-wise visual mode
C-V
for block-wise visual mode
Key Mappings
command
explanation
Leader
Spacebar
Leader + t
:tabnew
Leader + t + n
:tabnext
Leader + t + p
:tabprev
Leader + t + o
:tabo
**Leader + /**
:noh
Surround and Motion
Sneak
explanation
options
s{char}{char}
jump to the f
;next ,previous
{operator}z{char}{char}
jump to on the previous linence and carry out the operator.
; next , previous
w
move forward one word
b
backwards one word
W
move forward one WORD
B
backwards one WORD
Easy Motion
explanation
Leader Leader +w
Label the beginning of all words ahead
Leader Leader +f{char}
Label the beginning of {char} ahead
Leader Leader +b
Label the beginning of all words behind
Leader Leader +bd+w/b/f{char}
Label the beginning of all words bidirection
Leader Leader +e
Label the end of all words
Leader Leader +ge
Label the beginning of all words backwards
Leader Leader +j/k
Label the beginning of lines down/up
Multiple Cursors
explanation
gb
select a word, command to select others
switch to VISUAL mode
move up or down to set cursors
switch to VISUAL mode
move to the end or beginning to set cursors
Moving Around and Find
command
explanation
w
move forward one word
b
backwards one word
W
move forward one WORD
B
backwards one WORD
e
end of word
ge
go to the end of the previous word
gE
go to the end of the previous WORD
f{character}
(find) next {character}
F{character}
(find) previous {character}
t{character}
until next character
T{character}
until previous character
%
find matching
0
move to the fist character of a line
$
move to the end of the line
g_
move to the non-blank character at the end of a line
{
jump up one paragraph
}
jump down one paragraph
CTRL+D
Jump down one page
CTRL+U
jump up one page
Editing Text
command
result
d
delete
f or / or ?
find
c
change
t
unTil
r{char}
replace character under the cursor with {char}
R
replace more than one character, it functions like delete but acts on as many characters as you type.
Delete
command
result
dd
delete line
D
delete from cursor to end of line
dd
delete line
D
delete from cursor to line end
dw
delete word
d2W
delete two words
dt;
delete until ;
d/hell
delete until hell*
command
result
cw
change word
ci
change inner
ca
change around
ci
change inside quotes from line beginning
Insert and Append
command
result
i
insert before the cursor
a
insert after the cursor (append)
I
insert at the beginning of the line
A
insert at the end of the line (Append)
Three modified inserts
command
result
o
open a new line and insert
O
open a new line above and insert
gi
go to last insert change point and insert
Wow
Just realized the power of VIm in the following example. [[Vim Learn]].
// d + i=> wdtSpolite<ESC>fcdsipolite<ESPACE><ESC>
// c => wctSpolite<ESC>fccwpolitely<ESPACE><ESC>
constcourteousSalute=Icourteouslysaluteyougoodperson.";
well that example was nothing! Wait till you see what’s coming.
Write, Quit, Open
EX commands start with a :
:write saves the file
:quit closes the file if there are no changes
:edit creates or opens a new or existing file
Yank and Put
command
result
y{motion}
yank in a direction
yaw
yanks a word
yas
yanks a sentence
yap
yanks a paragraph
p
puts the after yanked
P
puts the yanked before the cursor
Search and replace
:#,#s/older/new/g where #,# are the line numbers of the range of lines where the substitution is to be done.
:%s/older/new/g to change every occurrence in the whole file.
:%s/older/new/gc to find every occurrence in the whole file,
% typing when on a bracket takes you to the matching bracket.
Visual Mode
command
explanation
v
for character-wise visual mode
V
for line-wise visual mode
C-V
for block-wise visual mode
Key Mappings
command
explanation
Leader
Spacebar
Leader + t
:tabnew
Leader + t + n
:tabnext
Leader + t + p
:tabprev
Leader + t + o
:tabo
**Leader + / **
:noh
Surround and Motion
Sneak
explanation
options
s{char}{char}
jump to the first occurrence
;next ,previous
{operator}z{char}{char}
jump to the first occurrence and carry out the operator.
; next , previous
Easy Motion
explanation
Leader Leader +w
Label the beginning of all words ahead
Leader Leader +f{char}
Label the beginning of {char} ahead
Leader Leader +b
Label the beginning of all words behind
Leader Leader +bd+w/b/f{char}
Label the beginning of all words bidirection
Leader Leader +e
Label the end of all words
Leader Leader +ge
Label the beginning of all words backwards
Leader Leader +j/k
Label the beginning of lines down/up
Multiple Cursors
explanation
gb
select a word, command to select others
switch to VISUAL mode
move up or down to set cursors
switch to VISUAL mode
move to the end or beginning to set cursors
Moving Around and Find
command
explanation
w
move forward one word
b
backwards one word
W
move forward one WORD
B
backwards one WORD
e
end of word
ge
go to the end of the previous word
gE
go to the end of the previous WORD
f{character}
(find) next {character}
F{character}
(find) previous {character}
t{character}
until next character
T{character}
until previous character
%
find matching
0
move to the fist character of a line
$
move to the end of the line
g_
move to the non-blank character at the end of a line
{
jump up one paragraph
}
jump down one paragraph
CTRL+D
Jump down one page
CTRL+U
jump up one page
Editing Text
command
result
d
delete
f or / or ?
find
c
change
t
unTil
r{char}
replace character under the cursor with {char}
R
replace more than one character, it functions like delete but acts on as many characters as you type.
Delete
command
result
dd
delete line
D
delete from cursor to end of line
dd
delete line
D
delete from cursor to line end
dw
delete word
d2W
delete two words
dt;
delete until ;
d/hell
delete until hell*
command
result
cw
change word
ci
change inner
ca
change around
ci
change inside quotes from line beginning
Insert and Append
command
result
i
insert before the cursor
a
insert after the cursor (append)
I
insert at the beginning of the line
A
insert at the end of the line (Append)
Three modified inserts
command
result
o
open a new line and insert
O
open a new line above and insert
gi
go to last insert change point and insert
Wow
Just realized the power of VIm in the following example. [[Vim Learn]].
// d + i=> wdtSpolite<ESC>fcdsipolite<ESPACE><ESC>
// c => wctSpolite<ESC>fccwpolitely<ESPACE><ESC>
constcourteousSalute=Icourteouslysaluteyougoodperson.";
well that example was nothing! Wait till you see what’s coming.
Write, Quit, Open
EX commands start with a :
:write saves the file
:quit closes the file if there are no changes
:edit creates or opens a new or existing file
Yank and Put
command
result
y{motion}
yank in a direction
yaw
yanks a word
yas
yanks a sentence
yap
yanks a paragraph
p
puts the after yanked
P
puts the yanked before the cursor
Search and replace
:#,#s/older/new/g where #,# are the line numbers of the range of lines where the substitution is to be done.
:%s/older/new/g to change every occurrence in the whole file.
:%s/older/new/gc to find every occurrence in the whole file,
% typing when on a bracket takes you to the matching bracket.
Visual Mode
command
explanation
v
for character-wise visual mode
V
for line-wise visual mode
C-V
for block-wise visual mode
Key Mappings
command
explanation
Leader
Spacebar
Leader + t
:tabnew
Leader + t + n
:tabnext
Leader + t + p
:tabprev
Leader + t + o
:tabo
**Leader + / **
:noh
Surround and Motion
Sneak
explanation
options
s{char}{char}
jump to the first occurrence
;next ,previous
{operator}z{char}{char}
jump to the first occurrence and carry out the operator.