// you’re reading...

How in the Tech

vi Cheat Sheet

vi is a powerful text editor found on practically every Unix based system. Consequently, it is quite beneficial to learn and master vi and its abundance of keyboard shortcuts. If you are not quite the guru you hoped to be, here is a handy reference page that will bring you up to speed quickly.

File Handling

vi

Open a  file to edit

:w
Save a file

:w
Save a file with a new filename

:q!
Quit without saving

:wq
Quit and save

Movement

h or (left arrow key)
Left one character

i or (right arrow key)
Right one character

k or (up arrow key)
Up one line

j or (down arrow key)
Down one line

^
Beginning of a line

$
End of  a line

1G
Beginning of a file

G
End of a file

:
move to line number

Editing

i
Insert text

A
Append text

r
Replace text

R
Replace a character

x
Cut/delete character

dd
Cut/delete line

D
Cut/delete to end of line

Y or yy
Copy line (yank)

p
Paste line

J
Join line below to this line

u
Undo last change

e
Undo all changes

Advanced Users

/ &/ (repeats last search)
Search for keyword

:set number & : set no number (turns off numbers)
Show line numbers

.
Repeat last command

:m//
Regular expression search

:s///
Regular expression replace

:,s///
Regular expression replace by lines

:
Repeat command x times

%
Find matching () or {}

:sh (type exit to return to vi)
Drop to shell

[tags]Unix, vi, Linux, vi shortcuts[/tags]

If you want to be notified the next time I write something please subscribe to my RSS feed. Thanks for reading!

Related Posts

Discussion

One comment for “vi Cheat Sheet”

Post a comment