VIM Hacks
🎯

VIM Hacks

🎯
VIM Hacks
code
Description
Category
Mode
Example
Tags
Company
zw
mark a good word as misspelled
Spell Checking
zq
mark a misspelled word as correct
Spell Checking
z=
browse suggestions on a misspelled word
Spell Checking
yt;
copy everything from here to the next ;
ysiw<em>
emphasize the current word (it works with text objects!) Want to know what's crazier about that? It's dot repeatable!.
Surround Actions
ysiw[
surround the current word with brackets
Surround Actions
yip
copy (inside) paragraph
y
yank (copy)
Verbs
Insert
x
exterminate (delete) from character under the cursor
Deleting Text
Normal
exterminate
X
exterminate (delete) the character before the cursor
Deleting Text
Normal
exterminate
w
word
Nouns
w
move forward one word
Moving By Word
W
move forward one big word
Moving By Word
vwwy
enter visual mode, select two or more words of text, and copy them
vhack
VS<p class="important”>
visually select the line, and surround it with the p tags
Vjjd
enter line-based visual mode, delete a couple of lines below
vhack
vipyjjd
visually select an entire paragraph, copy it, then paste it two lines below
vhack
vip
visually select entire paragraph
vhack
vi{
select inside curly brackets
vhack
vi(
select inside parenthesis
vhack
vi {file}
open your file in vim
file
v2i{
select everything inside the second tier braces (two levels out of the current nested set)
vhack
v
visually select (V for line vs. character)
Verbs
Normal
v
enter char-based visual mode
Visual
V
enter line-based visual mode
Visual
t<
jump forward and land right before the <
t
searches for something and stops before it
Modifiers
Normal
t
tag think (HTML/XML)
Nouns
t
jump up to a character
search
s {NOUN}
substitute from where you are to the next command (noun)
Changing Text
Insert
substitute
s
sentence
Nouns
S
select anything, and then type S. You'll be brought to the bottom of the window. Now type in what you want to wrap that with, such as <a href="/images">, and then press enter.
Surround Actions
S
substitute the entire current line
Changing Text
Insert
substitute
r
replace the one character under your cursor
Changing Text
Insert
replace
R
replace the character under your cursor, and continue typing
Changing Text
Replace
replace
qa
start recording a macro named “a”
Macros
q
stop recording
Macros
p
paragraph
Nouns
p
go anywhere and paste theme
vhack
o
open a new line below the current one
Changing Text
Insert
O
open. a new line above the current one
Changing Text
Insert
n.
go to the next instance and append the same text to that line
n
go to the next instance of the searched word
search
N
go to the previous instance of the searched word
search
M
move to the middle of the screen
Moving Within Window
l
move right one line
Basic Motions
Normal
Move Right One Line
L
move to the bottom of the screen
Moving Within Window
k
move up one line
Basic Motions
Normal
Movie Up One Line
j
move down one line
Basic Motions
Normal
Move Down One Line
J
join the current line with the next one (delete what’s in between)
Deleting Text
Normal
exterminate
iw
inside word
Combo Objects
it
inside tags
Combo Objects
is
inside sentence
Combo Objects
ip
inside paragraph
Combo Objects
i`
inside back ticks
Combo Objects
i{
inside curly brackets
Combo Objects
i(
inside parenthesis
Combo Objects
i"
inside double quotes
Combo Objects
i'
inside single quotes
Combo Objects
i
inside
Modifiers
Normal
i
insert before the cursor
Changing Text
Insert
insert
h
move left one line
Basic Motions
Normal
Move Left One Line
H
move to the top of the screen
Moving Within Window
gg
go to the top of the file
Moving Within Window
G
go to the bottom of the file
Moving Within Window
f<
jump forward and land on the < on this line
f
searches for that thing and lands on it
Modifiers
Normal
f
jump on to a character
search
e
move to the end of current word
Moving By Word
dt.
delete from where you are to the period
Deleting Text
Normal
exterminate
ds"
delete the double quotes around something
Surround Actions
ddp
swap position of two lines (next line swaps with current line)
hack
change
dd
delete the current line
Deleting Text
Normal
exterminate
d2w
delete two words
d {NOUN}
delete whatever you define as a noun, e.g. a word, or a sentence, or a paragraph.
Deleting Text
Normal
exterminate
d
delete
Verbs
Visual
Verbs
D
delete to the end of the line
Deleting Text
Normal
exterminate
CTRL Y
scroll down one line
Moving Within Window
CTRL v
enter paragraph-based visual mode
Visual
CTRL U
move up half a screen
Moving Within Window
CTRL o
jump back to where you were
CTRL i
jump to your previous navigation location
CTRL F
move down a page/screen
Moving Within Window
CTRL E
scroll up one line
Moving Within Window
CTRL D
move down half a screen
Moving Within Window
CTRL B
move up a page/screen
Moving Within Window
ct<
change everything from here to the <
ct?
change up to the question mark
Changing Text
Insert
change
cs]{
change the square brackets around something to curly brackets
Surround Actions
cs"’
for the word you're on, change the surrounding quotes from double to single
Surround Actions
cs'<q>
for the word you're on, change the surrounding single quotes to <q>
Surround Actions
cis
change inside sentence
c {NOUN}
change whatever you define as NOUN (movement), ie a word, a sentence of a paragraph
Changing Text
Insert
change
c
change
Verbs
Normal
C
change the current line from where you are at
Changing Text
Insert
change
b
block (think programming)
Nouns
b
move back one word
Moving By Word
B
move back one big word
Moving By Word
aw
around word
Combo Objects
at
around tags
Combo Objects
as
around sentence
Combo Objects
ap
around paragraph
Combo Objects
a`
around back ticks
Combo Objects
a{
around curly brackets
Combo Objects
a(
around parenthesis
Combo Objects
a"
around double quotes
Combo Objects
a'
around single quotes
Combo Objects
A {another word}
append some text to the end of the line of the searched word
a
around
Modifiers
Normal
a
append after the cursor
Changing Text
Insert
append
A
append at the end of the line
Changing Text
Insert
A this text
append
0i:j0vG.
repeat the last action on every line of the file
vhack
&
repeat the last exterminate command
Deleting Text
Normal
exterminate
/{word}
search for a word
search
/
find a string (literal or regex)
Modifiers
Command
*
search for other instances of the word under your cursor
search
@a
play back the macro
Macros
}
paragraph (another way of doing it)
Nouns
]s
go to next misspelled word
Spell Checking
[s
go to last misspelled word
Spell Checking
)
sentence (another way of doing it)
Nouns
’s
toggle spelling visuals
Spell Checking
’f
fix spelling
Spell Checking
:zz
write your changes and exit vim
Command
file
:wq
write your changes and exit vim
Command
file
:w
write your changes to the file
file
:saveas {~/path}
save your file to that location
Command
file
:s /foo/bar/g
change “foo” to “bar” on the current line
hack
replace
:q!
get out of vim (quit) without saving changes
Command
file
:${NUMBER}H
move to a given line number
Moving Within Window
Command
:%s/s+$//
delete Ctrl-M white spaces from the end of all files
hack
:%s /foo/bar/g
change “foo” to “bar” on every line
hack
replace
;
go to the next instance when you’ve jumped to a character
search
,
go to the previous instance when you’ve jumped to a character
search