Exit like a pro #
- Save and exit =>
ZZ
. - Save without saving =>
ZQ
.
Select inside () (Bracket) and {} (Curly Bracket) #
- Select within
()
=>vib
. - Select within
{}
=>viB
.
Edit multiple lines at once #
Step by step to insert at the beginning of the line:
Ctrl+v
to get visual mode.I
to insert mode.- Enter your HTML tag
<p>
. ESC
.
Step by step to insert at the end of the line:
Ctrl+v
to get the visual mode and select each line.$
sign to select to the end of paragraph.A
to append the closing tag</p>
.ESC
.
# AFTER
<p>paragraph one</p>
<p>paragraph two</p>
<p>paragraph three</p>
<p>paragraph four</p>
<p>paragraph five</p>
<p>paragraph six</p>
<p>paragraph seven</p>
# BEFORE
paragraph one
paragraph two
paragraph three
paragraph four
paragraph five
paragraph six
paragraph seven
Toggle between uppercase and lowercase #
- Use
~
to toggle the beginning character of the word. - Use
g + ~ + $
to toggle to the end of paragraph.
Reindent the whole file #
Press gg
to go to the top, then =
and G
to the bottom of the file.
Jump between (), [], {}, etc #
Use the %
sign to jump between those braces.
Suspend and restore vim #
- Press
Ctrl+z
to suspend vim in the background. - Type command
fg
to access vim.
Open URL or file under the cursor #
- Move your cursor under the URL and press
gx
to open in the default browser. - For file, do the same and replace with the
gf
.
Using vim mark and return to it #
Step by step to mark location:
- Type
m
to mark the current line. - Type
a
as the identifier. You can changea
with any identidier.
Step by step to return to marked line:
- Press
'
or single quote. - Press the identifier, for example
a
.
If you want to mark and jump of different file, use A
as identifier. So:
m
andA
.'
andA
.
Jump to specific line number #
Enter the line number, such as 12
, then G
.
Join lines #
Use J
to join two lines into single line.