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+vto get visual mode.Ito insert mode.- Enter your HTML tag
<p>. ESC.
Step by step to insert at the end of the line:
Ctrl+vto get the visual mode and select each line.$sign to select to the end of paragraph.Ato 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+zto suspend vim in the background. - Type command
fgto access vim.
Open URL or file under the cursor #
- Move your cursor under the URL and press
gxto 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
mto mark the current line. - Type
aas the identifier. You can changeawith 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:
mandA.'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.