To prepare for the Certified Kubernetes Administrator (CKA) exam, basic Linux skills are a necessity. Being able to move the cursor around quickly in the Bash shell and Vim, create aliases and handy environment variables helps saving precious time during the CKA exam.
Of course there are plenty of cheat sheets around, but creating one yourself that has the commands you like and use, forces you to learn them. I started this series to have cheat sheets of my own that have the generic commands, but also the specific ones for my Windows and MacOS devices if any.
While I was progressing it made sense to share my preparations, so hopefully it serves you well. If so, please like the series at the bottom.
The CKA prep series
Part 2 – Vim cheat sheet
Part 3 – Kubectl time savings (in progress)
Vim
There is time to win during the exam for fast text editing in Vim. KubeAcademy created a nice lesson for that. To do so, a couple of config changes to the .vimrc file in your home directory can make a huge difference.
" Set shift width to 2 spaces. " Set tab width to 2 columns. set tabstop=2 softtabstop=2 shiftwidth=2 " Use space characters instead of tabs. set expandtab " Show line numbers. set number ruler " Extra convenience when navigation deep levels in YAML. set autoindent smartindent " Increase readability through syntax highlighting. syntax enable " Enable type file detection, load plugins and indent for detected type. filetype plugin indent on
Let’s move on to the common keystrokes one needs to know. According to Vim, a word can be a group of letters, numbers, and underscores. On the other hand, a token is anything separated by whitespace and can include punctuation.
Action | Command | Description |
Navigation (command mode) | ||
Move the cursor back one character | h | Use 5h for 5 chars |
Move the cursor forward one character | l | Use 5l for 5 chars |
Move the cursor up one line | k | Use 5k for 5 lines |
Move the cursor down one line | j | Use 5h for 5 lines |
Move cursor to start of word or prev. word | b | Use B for token instead of word |
Move cursor to end of word or next word | w | Use W for token instead of word |
Move cursor to end of word | e | Use E for token instead of word |
Move cursor to start of line | 0 | |
Move cursor to end of line | $ | |
Move cursors to first (non-blank) char | ^ | |
Move cursor to top of file | gg | |
Move cursor to end of file | G | |
Move cursor to specific line | 5G | Use 5G or :5 to move to line 5 |
Navigating screens (command mode) | ||
Move cursor to top of screen | H | (High) |
Move cursor to middle of screen | M | (Middle) |
Move cursor to bottom of screen | L | (Low) |
Move cursor forward one screen | CTRL + f | (Forward) |
Move cursor forward half a screen | CTRL + d | |
Move cursor back one screen | CTRL + b | (Back) |
Move cursor back half a screen | CTRL + u | |
Editing (insert mode) | ||
Insert text | i | Insert mode before the cursor |
Exit text insert | ESC | Exit insert mode |
Editing (command mode) | ||
Yank (copy) current line | yy | Use 5yy for 5 lines |
Delete (cut) current line | dd | Use 5dd for 5 lines |
Paste | p | After cursor |
Undo | u | (Undo) |
Redo | CTRL + r | (Redo) |
Selecting (visual mode) | ||
Select text in char mode | v | |
Select text in line mode | V | |
Select text in block mode | CTRL + v | |
Yank (copy) marked text | y | |
Delete (cut( marked text | d | |
Paste text | p | |
Change to lowercase | u | |
Change to uppercase | U | |
Searching (command mode) | ||
Search next instance of word | * | |
Search prev instance of word | # | |
Search forward for pattern | /patten | |
Search prev for pattern | ?pattern | |
Continue search in same direction | n | |
Continue search in opp direction | N | |
Save and exiting (command mode) | ||
Save file and continue | :w | |
Save and quit | :wq | |
Save to new and continue new | :sav | |
Save to new and continue prev | :w new_filename | |
Quit | :q | |
Quit without saving | :q! | |
Advanced editing (command mode) | ||
Paste text without indenting | :set paste | Prepare to insert copied text from website |
Indent a text section | V, Select lines, > (or) 2> | Single (or multi) indent a whole section at once. Use 2> for multiple indents |
Show hidden tabs | :set list | Shows hidden tabs (as ^I) that can cause kubectl parsing errors |
Replace hidden tabs | :retab | Replaces hidden tabs (as ^I) with spaces. Most used after “:set list” |
Useful links
Vimrc Configuration Guide – How to Customize Your Vim Code Editor
KubeAcademy: How to Prepare for the CKA Exam – Lesson 4 – Editing YAML with Vim
0 Comments