Vim
The best $EDITOR
.
Learn
- Touch typing
vimtutor
:help user-manual
- YT: Mastering the Vim Language
- #todo Practical Vim by Drew Neil
💡 Hint
MapCaps Lock
toESC
for easier switching to Normal mode.
Language
Modes:
- Normal: default (enter with
Esc
) - Insert: edit text (enter with
i
,a
, etc.) - Visual: select characters (enter with
v
) - Visual (lines): select lines (enter with
V
) - Visual (block): select blocks (enter with
Ctrl+v
) - Command: run builtin/external commands (enter with
:
)
Editing:
- A motion moves the cursor (e.g.
w
moves to the next word). - An operator changes the text (e.g.
d
deletes the text). - Motions and operators combined together operate on the text that was moved over (e.g.
dw
deletes to the next word). - A number before a motion/operator repeats it that many times (e.g.
3dw
deletes the next 3 words). - An operator repeated twice operates on the current line (e.g.
dd
deletes the current line). - An uppercase operator operates on the rest of the current line (e.g.
D
deletes the rest of the line). - An uppercase motion includes non-alphanumeric characters such as punctuation and brackets.
- Some operators operate immediately (e.g.
x
), others require a motion (e.g.d
). - A text object represents a text token (e.g. word, sentence, paragraph).
- An operator can operate (i)nside or (a)round a text object (e.g.
diw
deletes only the current word,daw
deletes also the surrounding whitespace). - A buffer is some text in memory. A window is a viewport on a buffer. A tab is a set of windows.
Motions:
hjkl
: left/down/up/rightw
: to the start of the next worde
: to the end of the next wordb
: to the start of the previous wordge
: to the end of the previous wordf<c>
: to the nextc
charactert<c>
: to the character before the nextc
character;
/,
: repeat the previousf
/t
jump forward/backward0
: to the start of the line$
: to the end of the line^
/_
: to the first non-blank character of the line%
: to the matching bracketgg
: to the first lineG
: to the last line<n>gg
: to the nth line(
/)
: to the previous/next sentence{
/}
: to the previous/next paragraphCtrl+o/i
: to the previous/next positionCtrl+b/f
: page up/downCtrl+u/d
: half page up/down- (Visual)
o
: to the other end of the selection
Operators:
i
: insert before the cursora
: insert after the cursorI
: insert at the start of the lineA
: insert at the end of the lineo
/O
: insert below/above the liney
: yank the textc
: change the textd
: delete the textp
: put the previously yanked/changed/deleted textx
: delete the characters
: delete the character and insertr<c>
: replace the character withc
J
: join two lines~
: switch case of the characterg~
: switch casegu
/gU
: to lower/upper casegv
: repeat the last selection>
/<
/=
: indent/unindent/autoindentu
: undo the last changeCtrl+r
: redo the last change.
: repeat the last change
Text objects:
w
: words
: sentencep
: paragrapht
: tagb
: synonym for(
/)
B
: synonym for{
/}
- any bracket
- any quote
Tricks:
ea
: append to the wordxp
: swap two charactersddp
: swap two linesgg=G
: autoindent the whole buffer
Search:
/
/?
: search forward/backward*
/#
: search the current word forward/backwardn
/N
: to the next/previous result
Replace:
:s/old/new
: replace in the current line:%s/old/new
: replace in the whole buffer:'<,'>s/old/new
: replace in the selection- Modifiers:
g
(all),c
(confirm)
Commands:
:q[uit]
: quit Vim:w[rite]
: write changes:e[dit]!
: discard changes:e[dit] <file>
: edit file:!<cmd>
: run an external commandCtrl+z
: suspend Vim (resume withfg
)
Registers:
"
: unnamed register (default)<a-z>
: named registers<A-Z>
: named registers (append)<1-9>
: delete queue0
: the last yank/
: the last search:
: the last command+
: system clipboard_
: black hole register
Macros:
q<a-z>
: record a macro (q
to stop recording)@<a-z>
: play a recorded macro@@
: replay the last macro
Neovim
A community-driven fork of Vim.
Features:
- Configurable with Lua
- Builtin support for LSP and Treesitter
Setup: