Skip to content

Instantly share code, notes, and snippets.

@Piotr1215
Last active January 31, 2022 22:12
Show Gist options
  • Save Piotr1215/0a1ccd30efe38ed2de829c315a0fc355 to your computer and use it in GitHub Desktop.
Save Piotr1215/0a1ccd30efe38ed2de829c315a0fc355 to your computer and use it in GitHub Desktop.
Vim Commands

Vim Commands

Useful commands for CKA/CKAD/CKS exams

Command Description
Shift + A go to the end of the current row (insert mode)
Shift + C delete everything after the cursor (insert mode)
Shift + I go to the first letter on the current row (insert mode)
Shift + G go to the last row of data in the file
Ctrl + O Go back to lines
Ctrl + I Go forward
Ctrl + D Commands completion
/search Find stuff
* Search for other instances of the same word/char
. Repeat last executed command
e jump to the end of the next word
w jump to the start of the next word
:40 Goto line in the file
wd Delete word
d$ Delete from cursor
3dd Delete 3 lines
v, V Select, Select block
r, R Replace single char, replace from cursor
o, O Open a new line below o and above O the cursor
dG Delete from the cursor to the end of file
gg Go to the first-line
gf Go to fule under cursor
g;, g, Go to previous or next edit place in the file respectively first-line
G Got to the last line
u Undo, revert
:%s/old/new/g replace old with new in whole file
_ (underscore) Get to the first non-blank character of current line
:! command ENTER execute any command
:e filename Open another file
: ls List all open files
:b # Swap to file where # is file number
:w name save the current file under certain name
:r filename place content of a file where the cursor is positioned
:% s/old_text/new_text/g Execution mode, replace all old_text with new_text throughput file

Useful Gestures

Copy to end of the line and paste with replace

copy: yg_
paste: vg_p

Copy to clipboard registry and paste

Should also work with +

copy: "*y
paste: "*p

Copy something, delete someting else and paste the first thing

The black hole register "_ will do the trick, but there is a better solution:

When you enter the line back with the p command you are pasting the contents of the (volatile) default register "", which has been overwritten by dd. But you still can paste from the (non volatile) yank register "0, which won't be overwritten by the delete command dd.

So these are the commands you want to use as per your example:

yy
dd
"0p

Additional Setup

Edit vim config file and set:

  • line numbers, this is helpful when kubeclt detects an error on a specific line of the file
  • tabs to spaces, use tab to set YAML indentation, it will be converted to spaces

vim ~/.vimrc - create vim config file

autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment