I really enjoy using the console. Not only on my Mac, but also frequently on remote systems. And here I constantly switch between the editors vi and nano.

Unfortunately, I am also a very forgetful person and keep forgetting the same keyboard shortcuts or mixing them up. So what could be more obvious than creating little cheat sheets of the most frequently used shortcuts as a reminder?

Here we go...

Cheat Sheet: nano

ActionKeys
Line startCtrl+A
Line endCtrl+E
Document startOption+\\
Document endOption+/
Page upCtrl+Y
Page downCtrl+V
Go to line/columnCtrl+_
ActionKeys
Search forwardCtrl+W
Next matchOption+W
ReplaceCtrl+\\
Search options (prompt)Option+C (Case) • Option+R (Regex)

Editing

ActionKeys
Cut (line)Ctrl+K
Uncut (paste)Ctrl+U
CopyOption+6
Mark textCtrl+^
Undo / RedoOption+U / Option+E

File / Program

ActionKeys
Write out (save)Ctrl+O
Read file (insert)Ctrl+R
ExitCtrl+X
Cancel / abort inputCtrl+C

Misc

ActionKeys
HelpCtrl+G
Justify (align)Ctrl+J
Spell checkCtrl+T
Execute commandCtrl+R , Ctrl+X

You can download a PDF version of the nano cheat sheet here.

Cheat Sheet: vi

ActionKeys
Line up / downk / j
Word forward / backwardw / b
Line start / end0 / $
File start / endgg / G
Page up / downCtrl+b / Ctrl+f

Modes

ActionKeys
Insert (line start)iI
Insert (line end)aA
New line (above)O
New line (below)o
Visualv (char) • V (line) • Ctrl+v (block)
Back to normal modeEsc

Editing

ActionKeys
Deletex (char) • dd (line) • d + motion
Yank (copy)yy (line) • y + motion
Pastep (after) • P (before)
Changec + motion • cc (line)
Repeat / Undo / Redo. / uCtrl+r

Search & Replace

ActionKeys
Search forward / backward/ pattern • ? pattern
Next / previous matchn / N
Word under cursor* / #
Replace in file:%s/old/new/g • confirm: :%s/old/new/gc

Files & Buffers

ActionKeys
Save / Quit:w:q:wq:q!
Open / reload file:e file:e!
Switch buffer:bn / :bp:b nr|name
Split / vsplit:split:vsplit
Switch between splitsCtrl+w h/j/k/l
Close split / only this:q:only

You can download a PDF version of the vi cheat sheet here.