Vi and co Flashcards
Navigation
h , j , k , l
think of position on keyboard
l : moves the cursor to the RIGHT
h: (symmetrically opposite) moves cursor to the LEFT
k : moves cursor to the line ABOVE
j : (symmetrically opposite) moves cursor one line DOWN
Navigation
w , e , b
think of 1st letter of
w : next word in line
e : end of next word on same line
b : beginning of next word on same line
Other useful keystrokes
:q!
:w
ZZ
:e!
:!
:q! quit without saving changes
:w write => save changes while staying in vi
ZZ no semicolon and capitals writes the file and exits
:e! reloads the file abandoning changes made
:! run a shell command from the vi screen
NOTE: the semicolon moves the cursor to the bottom of the screen to write out command.
Insert, edit etc.
i
o
cw & c$
dw & d$
dd
x
i : insert
o : insert a line under the current line. O for the line above
cw : place cursor in a word and deletes the part to the left of the cursor. NOTE insert mode is entered subsequent.
c$ : with c$ the rest of the line to the left of the cursor is deleted. NOTE insert mode is entered subsequently.
dw : same as cw but without insert mode butting in
d$ : like c$ without the insert mode butting in
dd : deletes the cursor’s current line
x : deletes character at the cursor position
Search
/
?
n
/ (followed by string) searches forward in opened file
? (followed by string) searches backward in opened file
n repeats search (forwards or backwards)
From inside vi
:help <command></command></command>
you’re in a file opened with vi
type :help wrap
the help for the command wrap is opened and can be scrolled through.
to leave help type :q
So when do I use the ESC key?
When you want to exit the INSERT mode that you enter by typing i
By default you are in the COMMAND mode which allows you to move around, delete characters insert lines etc but not insert stuff.