Still, one of the best text editing tools in a console-only environment when speed and productivity matters.


Edit file (vi/vim)
vi (filename)
vim cluster.yml

Edit multiple files same window split side by side (must use vim)
vim -O (filename1) (filename2) (filename...)

Edit multiple files same windows split stacked vertically (must use vim)
vim -o (filename1) (filename2) (filename...)
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

Search / Replace

/(str) --> search for (str)
: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


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
2} --> move next 2 paragraphs

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


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

Press V to enter Visual mode
Move cursor to highlight text
Press d to cut, y to copy
Move to target position
Press P to paste after cursor, p to paste before cursor


: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