Essential Vim commands for editing Kubernetes YAML on the server.
Open and Exit
vi filename.yaml # open file
vim filename.yaml # open file (better)| Command | What it does |
|---|---|
:w | Save |
:q | Quit |
:wq | Save and quit |
:q! | Quit without saving |
:wq! | Force save and quit |
Navigation (Normal mode)
| Key | What it does |
|---|---|
h j k l | Left, down, up, right |
gg | Go to top of file |
G | Go to bottom of file |
Ctrl+F | Page down |
Ctrl+B | Page up |
0 | Start of line |
$ | End of line |
:10 | Go to line 10 |
Editing (Normal mode)
| Key | What it does |
|---|---|
i | Insert before cursor |
a | Insert after cursor |
o | New line below |
O | New line above |
dd | Delete line |
yy | Copy line |
p | Paste below |
u | Undo |
Ctrl+R | Redo |
x | Delete character |
Search and Replace
/text " search forward
?text " search backward
n " next match
N " previous match
:%s/old/new/g " replace allYAML Specific
>> " indent line right
<< " indent line leftUseful for Kubernetes
# Open and go straight to line 10
vi +10 file.yaml
# Open and search for a term
vi +/image file.yamlThe .vimrc for YAML
Add to ~/.vimrc for correct YAML behaviour from our GitHub or Forgejo
(Visited 11 times, 1 visits today)

