Sitemap

5 .vimrc options for the CKA exam and everyday editing

5 min readOct 8, 2026

--

Press enter or click to view image in full size

In the CKA exam you spend a lot of time inside Vim: kubectl edit, kubectl ... --dry-run=client -o yaml > pod.yaml followed by vim pod.yaml, and manifests pasted from the Kubernetes documentation. The exam terminal is a plain shell, and you are allowed to edit ~/.vimrc. Two minutes spent on it at the start of the exam saves many more later, and the same 10 lines make Vim nicer for ordinary work too.

Why YAML makes this matter: indentation is the syntax, it must be made of spaces, and a single tab character makes kubectl apply reject the whole file:

error: error parsing pod.yaml: error converting YAML to JSON:
yaml: line 12: found character that cannot start any token

We start from an empty ~/.vimrc and add one option at a time. Each step explains the problem the option solves, gives the line to add, and then shows the effect in a real file. The file used in every screenshot is sample/pod.yaml from this repository, a small Pod manifest with enough nesting to show indentation.

Get Ahmed Mansouri’s stories in your inbox

Join Medium for free to get updates from this writer.

Two things to know before the first step:

  • ~/.vimrc is read when Vim starts. After adding a line, quit and reopen the file to see the change, or type the same command inside Vim prefixed with a colon (:set number) to try it without restarting.
  • On many Linux distributions Vim loads a file called defaults.vim only when you have no ~/.vimrc. The moment you create one, those defaults disappear and Vim behaves like plain vi. That is why some of the options below are things you may have "already had": once you own a .vimrc, you must ask for them yourself.

Step 0: start empty

cat ~/.vimrc
vim sample/pod.yaml

1. set number

Every error you get from Kubernetes points at a line: yaml: line 12, error validating data: ... line 7. Without line numbers you count by hand. With them you read the number, type :12 and you are there. Day to day it is the same: compiler output, stack traces, code review comments and colleagues all talk in line numbers.

set number

Try it. Open the file, then jump with :12 (or 12G).

2. set expandtab

By default, pressing Tab inserts a real tab character. YAML forbids tabs for indentation, so one Tab press in a manifest is enough to produce the found character that cannot start any token error above, and the broken character is invisible on screen. expandtab makes the Tab key insert spaces instead, so the mistake becomes impossible to type.

set expandtab

3. set tabstop=2

Kubernetes manifests use two spaces per level. Vim’s default is eight, so after step 2 a Tab press inserts eight spaces: valid YAML, but four levels deep instead of one. tabstop sets how many columns a Tab represents; with expandtab on, that is how many spaces the Tab key inserts.

set tabstop=2

Try it. Place the cursor at the start of an empty line, press Tab once, and the cursor moves two columns instead of eight.

4. set shiftwidth=2

The Tab key is not the only way to indent. >> and << shift a line, > and < shift a visual selection, and Ctrl-T / Ctrl-D shift while typing in insert mode. All of them move by shiftwidth, which is independent of tabstop and also defaults to eight. Set it to two as well, and re-indenting a whole pasted block becomes: select it with V, press > once.

set shiftwidth=2

Try it. Put the cursor on containers:, type V and move down to the end of the container block, then press >. The block moves exactly two columns to the right; < moves it back.

Press enter or click to view image in full size
Press enter or click to view image in full size

5. set autoindent

When you press Enter after containers: you want the new line to start at the same depth, not at column 1. Without autoindent every new line starts at the left margin and you re-type the indentation each time. With it, the new line copies the indentation of the line above; use Ctrl-T to go one level deeper and Ctrl-D to come back out, both in insert mode.

set autoindent
Press enter or click to view image in full size
Press enter or click to view image in full size

The complete .vimrc

set number
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent

5 lines, nothing to install.

Conclusion

In this article we started from an empty .vimrc and added five options, one at a time, each solving a real problem you meet when editing Kubernetes manifests: set number to jump straight to the line kubectl complains about, set expandtab so a Tab press can never put a forbidden tab character into your YAML, set tabstop=2 and set shiftwidth=2 so every Tab press, >> and re-indent moves by the two spaces Kubernetes expects, and set autoindent so each new line starts at the right depth without retyping it.

These five lines take less than a minute to add at the start of the CKA exam, and they remain just as useful afterwards for any YAML, script or config file you edit. Keep them in your ~/.vimrc, and let Vim handle the indentation while you concentrate on the task.

Thank you for reading! 📝 Stay tuned for my next blog 🚀!

If you found the post enjoyable and helpful, WHY LEAVE WITHOUT ANY REACTION 😔? At least show your support by clapping (up to 50! 👏), leaving a comment, and following me. 😄

If you have any questions or feedback about this blog, please feel free to reach out to me on Linkedin.

💬 Linkedin: https://www.linkedin.com/in/ahmed-mansouri-a54637141

--

--