Vim Practical Reference
Vim Practical Reference
Advanced Editing Techniques
Vim offers a plenty of advanced editing techniques that can significantly boost productivity and efficiency. This section delves into some of these techniques, providing detailed descriptions and examples.
Text Objects
- Words: Use
daw
to delete a word,ciw
to change inside a word (from cursor to end). - Sentences: Use
das
to delete a sentence,cis
to change inside a sentence. - Paragraphs: Use
dap
to delete a paragraph,cip
to change inside a paragraph.
Advanced Movement
- Jump to Matching Bracket: Press
%
. - Beginning of Next/Previous Function: Use
]]
and[[
in code. - Jump to a Specific Character: Press
f
followed by the character (e.g.,fa
to jump to next 'a').
Macros
Recording: Press
q
followed by a letter to start recording,q
again to stop.Playback: Press
@
followed by the same letter to playback.- Example:
qd
(start recording to register d), perform actions,q
(stop recording),@d
(playback).
- Example:
Visual Block Mode
- Entering: Press
Ctrl + v
. - Editing Multiple Lines: Select a block and perform actions like insert (
I
) or append (A
).
Folding
- Creating a Fold: Select lines in Visual mode, then
zf
to create fold. - Opening/Closing Folds: Use
zo
to open andzc
to close a fold.
Marks and Jumps
- Setting a Mark: Press
m
followed by a letter (e.g.,ma
). - Jumping to a Mark: Press
'
followed by the letter (e.g.,'a
).