Vim For Managing Kubernetes Clusters

Essential Vim commands for editing Kubernetes YAML on the server.

 

Open and Exit

vi filename.yaml      # open file
vim filename.yaml     # open file (better)
CommandWhat it does
:wSave
:qQuit
:wqSave and quit
:q!Quit without saving
:wq!Force save and quit

Navigation (Normal mode)

KeyWhat it does
h j k lLeft, down, up, right
ggGo to top of file
GGo to bottom of file
Ctrl+FPage down
Ctrl+BPage up
0Start of line
$End of line
:10Go to line 10

Editing (Normal mode)

KeyWhat it does
iInsert before cursor
aInsert after cursor
oNew line below
ONew line above
ddDelete line
yyCopy line
pPaste below
uUndo
Ctrl+RRedo
xDelete character

Search and Replace

/text           " search forward
?text           " search backward
n               " next match
N               " previous match
:%s/old/new/g   " replace all

YAML Specific

>>              " indent line right
<<              " indent line left

Useful for Kubernetes

# Open and go straight to line 10
vi +10 file.yaml

# Open and search for a term
vi +/image file.yaml

The .vimrc for YAML

Add to ~/.vimrc for correct YAML behaviour from our GitHub or Forgejo

(Visited 11 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.