Vi Vim Cheatsheet
Vi Vim Cheatsheet
Vi Vim Cheatsheet
vi/vim
Table
of
Contents
Introduction
.................................................................................................................................................
1
Command
Mode
..........................................................................................................................................
2
Insert
Mode
.................................................................................................................................................
2
Ex
Mode
.......................................................................................................................................................
3
Introduction
VI/Vim
is
a
text
editor
that
is
upwards
compatible
to
Vi.
When
using
Vi
throughout
the
Linux
Academy
we
are
really
using
a
low
level
VIM
utility.
Full
versions
of
VIM
can
be
installed
with
apt-get
install
vim
or
yum
install
vim.
Vi
is
an
important
text
editor
because
it
is
usually
always
available
on
systems
and
systems
in
recovery
mode.
Vi/VIM
is
a
very
powerful
text
editor.
This
cheat
sheet
relates
to
the
Linux+
and
LPIC
Level
1
exam
requirements.
Important:
Command
mode
is
the
mode
you
are
in
when
opening
or
editing
any
file
in
vi.
To
navigate
between
modes
hit
esc
first,
then
what
you
want
to
do.
Hitting
esc
will
take
you
back
to
command
mode.
You
need
to
be
in
command
mode
before
entering
ex
mode
or
insert
mode.
Example:
after
your
done
editing
text
hit
the
esc
key.
This
takes
you
to
command
mode
where
you
can
navigate
the
file.
If
you
want
to
go
from
insert
mode
to
ex
mode,
once
in
insert
mode,
in
the
esc
key
and
then
hit
the
:
key.
This
process
will
exit
from
insert
mode
back
to
command
mode
where
you
hit
the
:
key
to
open
ex
mode.
This
guide
is
meant
to
go
with
the
linuxacademy.com
videos
on
Vi.
For
more
explanation
and
examples
please
review
that
video.
Command
Mode
Command
mode
accepts
commands
which
are
usually
in
the
form
of
individual
letters
such
as
a
and
i.
You
can
use
h,
j,
k
and
I
to
navigate
files
in
similar
ways
as
the
up
and
down
arrow
on
a
keyboard.
You
can
also
use
the
up
and
down
arrow
on
a
keyboard.
Insert
Mode
Insert
mode
allows
you
to
add/edit
text
inside
of
the
file.
As
stated
under
command
mode
options
above,
there
are
different
ways
to
insert
into
insert
mode.
Depending
on
what
command
is
issued
depends
on
how
you
enter,
such
as,
replacing
a
word,
starting
a
line
above
or
below
a
cursor
etc.
Inserting
into
insert
mode
from
command
mode
i
insert
text
and
not
replace
it
R
over
write
existing
text
when
new
text
added
cw
remove
current
word
cursor
is
on
and
insert
into
insert
mode
to
add
text
cc
replace
the
entire
of
line
of
text
Ex
Mode
You
enter
ex
mode
by
typing
a
:
this
will
open
on
the
bottom
of
the
screen
a
command
prompt
starting
with
a
:
ex
mode
is
used
for
saving
and
manipulating
files.
It
is
very
powerful;
you
can
even
browse
the
Linux
command
line
from
this
mode,
load
files
into
your
file,
and
other
powerful
actions.
You
must
be
in
command
mode
before
entering
into
ex
mode.
Searching
and
Replacing
Text
Vi/Vim
allows
you
to
search
and
replace
text
much
like
the
SED
editor.
:%s/user/root
will
replace
the
first
occurrence
of
user
on
each
line
of
the
file
with
root
:%s/user/root/g
will
replace
all
occurrences
of
user
with
root;
adding
the
g
means
global
:w
saves
changes
:wq
saves
changes
and
quits
:q
quits
without
saving
changes
:e
/file.txt
will
load
the
new
file.txt
into
the
vi
editor
for
editing.
This
will
only
occur
if
the
current
changes
to
the
file
being
edited
are
saved
:r
allows
you
to
bring
contents
of
an
old
file
into
a
new
one
:!
Allows
you
to
run
shell
commands
from
within
vi
example:
!ls
/etc