Malcolm 'Max' DeRungs



vi (filename) open file with VI
vi -O (filename) (filename) ... open multiple side-by-side windows
vi -o

vim cluster.yml
vim -p sharepoint_qa_job.yaml sharepoint_app_creds_qa.yaml

The ^ character means the Ctrl or control key. Use ^w> and ^w< to navigate between side-by-side windows

Close / Quit

:q quit
:qa quit all windows
:q! quit and discard
:qa! quit and discard all windows
:w (filename) save as filename
:wq write to buffer and quit
:wqa write to buffer and quit all
:wqa! write to r/o buffer and quit all
:x save + quit
:sp filename new split frame window

^w go to next window


l right one character
h left one character
k up one line
j down one line
0 beginning of line
$ end of line
w W beginning of next word / bigword
e E end of next word / bigword
b B beginning of prev word / bigword
( ) beginning of prev / next sentence
{ } beginning of prev / next paragraph

3l move right 3 characters
4) move next 4 sentences
2b move prev 2 words
12} move next 12 paragraphs

^b page up
^f page down
#g go to line number
n N repeat search / backward

/(str) search for (str)


Variations on cut, copy, paste that modify text from command mode

d% delete, y% yank, c% replace

dd yy cc current line and newline
d$ y$ c$ from cursor to end of line
d^ y^ c^ from cursor to start of line
dG yG cG all lines from cursor to bottom of doc
dgg ygg cgg all lines from cursor to top of doc
kdgg kygg kcgg all lines above cursor
d(move) y(move) c(move) from cursor to (move)
diw yiw ciw current word
dw yw cw to start of next word
d3w y3w c3w next 3 words
3dd 3yy 3cc next 3 lines
d) y) c) remainder of sentence
d} y} c} remainder of paragraph

d% y% c% to matching ( ), { } and [ ] character

J join next line to end of line
X delete char under cursor
r(char) replace (character) under cursor
u undo!
. repeat last command


These commands put you in insert mode. Here you can type in text, return for new line, arrow keys to move cursor, and delete. Get back to command mode with esc.

i a edit before / after cursor
I A edit at beginning of line
o O add new line below / above, then insert

^A to edit

Cut / Paste

  1. Press V to enter Visual mode
  2. Move cursor to highlight text
  3. Press d to cut, y to copy
  4. Move to target position
  5. Press P to paste after cursor, p to paste before cursor

Search / Replace

:s/reg/rep first match current line
:s/reg/rep/g all matches current line
:%s/reg/rep/g all matches globally
:%s/reg/rep/gc all matches globally w/ prompt


^D <-
:set autoindent turn on indentation
:set tabstop=(num) set tab size
:set nu turn on line numbers
:set nonu turn off line numbers
:set h turn on highlighting
:set noh turn off highlighting

To always show line numbers -> add ":set number" to ~/.vimrc

Ctrl+z followed by kill %1 to kill session
ZQ to eliminate "Output not to a terminal" warning