Previous: Vim for CKAD - exercise 2 - append text, save as

Vim is great if we invest time to learn to use it. Editing Kubernetes YAML files in Vim should be as natural as breathing.

Getting Started with Vim for CKAD exam

First things first

Put your mouse away, forget you have a touchpad and keep your hands on the keyboard.

Open an existing file in Vim

vim vimisawesome.yaml

The text reads something like this

Vim is awesome. Because it really is!

Keep the existing text and open a new line below the current line - aka start writing below this line

o

o opens a new line lower (as in lowercase o) than the current one and switches to INSERT mode, allowing us to start writing

Start writing at the current cursor position

A new line has opened low below the current line.

ESCape from INSERT mode and return to NORMAL mode before proceeding to the next step.

ESC

Keeping the existing text Open a new line above the current line - aka start writing above this line

O

O Opens a new line up (as in uppercase O) abOve the current one and switches to INSERT mode, allowing us to start writing.

Start writing at the current cursor position

A new line has opened up abOve the current line.

ESCape from INSERT mode and return to NORMAL mode before proceeding to the next step.

ESC

Now that the exercise pattern is clear, practice these most commonly used INSERT mode commands

Start writing – remember to ESCape from INSERT mode after each write.

right where you are

i

before the first non-blank character on this line (Initial)

I

move to position 0 and start writing right there aka before the first character on this line

0i

Append after the last character on this line

A

after this character aka one character to the right

a

on a new line up abOve the current line

O

on a new line low below this line

o

from the Start of this line but delete all the text

S

right where you are but delete the selected character

s

Clear (delete) everything from the cursor to the end of this line and start writing (enter INSERT mode)

C

Combining INSERT mode commands with movements up k and down j

Append to the end of the existing line above

kA

at the beginning of the existing line above (Initial)

kI

Append to the end of the existing line below

jA

at the beginning of the existing line below (Initial)

jI

ESCape from INSERT mode

ESC

write (save) the document if you want to

:w

Alternatively, if you don’t want to write the document, close it without saving aka - quit forcefully (!)

:q!

Vim quits, closing the edited document, discarding all changes.

Congratulations!

Practice these steps to make editing YAML files in Vim second nature.

Next: Vim for CKAD - exercise 4 - hide, show vim