- Use
nano
if available- But
vi
is (almost) always there- Good to know the basics "just in case"
vi
is a "modal" editor
- In "command" mode to start
- Need to go into "insert mode" to insert new text
- Confusing to almost everyone at first
d
- "delete"b
- "jump 'back' one 'word'"i
- enter "insert" modeESC
- exit "insert" modedw
- "delete 'word'"3dw
- "delete 3 'words'"
:q!
- exit without savingu
- "undo" command3u
- "undo" last three changesview
- "read-only" version ofvi
- Arrow and page keys tend to work right
- Except in insert mode!
0
- jump to beginning of line$
- jump to end of linew
- jump forward a "word"b
- jump backward a "word":0
- jump to beginning of fileG
- jump to end of file
/foo
- find "foo" from cursor forward?foo
- find "foo" from cursor backwardn
- find next instance of last searchp
- find previous instance of last search
All of the following enter "insert mode":
i
- at cursorI
- at beginning of lineA
- "append" at end of lineo
- insert line below (lowercase) current lineO
- insert line above (uppercase) current lineESC
- exit insert mode
d
- "delete" is same as "cut"dd
- delete/cut current line3dw
- delete/cut three "words"
y
- "yank" is the same as "copy"yy
- yank/copy current line3yw
- yank/copy three "words"
p
- paste contents of buffer at cursorP
- paste contents of buffer above (uppercase) current lineu
- remember "undo" when you need it!
You can constrain the lines you want to affect by a command by "marking" a "range":
- Mark line with
m
command followed by a character- Mark another line with
m
command, but with a different label character- Use the
'
character to reference a label:'m,'ns/This/That/
:1,$!sort
:'m,'n!sort