vim keybindings
By far the most useful key bindings i have been able to learn till now:
navigation and exit
- h, j, k, l → left, down, up, and right
- :q → exit vim
- :q! → exit vim without saving
- :wq → exit vim after saving changes
- gg → move to the first line in the file
- shift + g (G caps) → bottom of the file!
- 0 → go to first character of the line
- $ → last character of the line
deletion
- dd → deletes curr line and copies it to register
- {x}dd → deletes x lines from curr line
- d + shift + g (or dG) → deletes from the current cursor pos to the end of the file
- dgg → deletes everything from bottom line to top!
copy, paste, redo and undo
- yy → cp the line (yank in vim terminology 🙂)
- {x}yy → cp x lines from curr line
- :%y+ → cp entire file in VIM to clipboard
- p → pastes copied lines after the cursor
- u → undo
- ctrl + r → redo changes
search, replace
- r + {whatever you want to replace it with where the cursor is} → replace at the position where the cursor is
- / → search in the file
- :%s/{word to be replaced}/{replacement word} → find and replace in the file
tips:
- when you use the —h or help commands on cli or any command that prints a lot of ouput on the screen, pipe it with the less command to use the ouput in the reader and navigate using hjkl
k run -h | less
- to search something specific in the cli docs, use the following technique
k run -h | less
then as the docs open press / and the term you want to search for! ex- /dry-run and use the n → next result and N → prev result 3. when pasting something from docs into vim, the indentation may get messed up, to correct that when in esc mode use the below command and then in insert mode paste your content to preserve the indentation
:set paste
Links:
202508212317