-
To open a file/create a new file using vi:
vi FILE_NAME.c
-
To switch to
EDIT MODE
, pressESC
. -
To switch to
INSERT MODE
, pressi
. -
To save a file, go to
EDIT MODE
and write::w
-
To save a file and exit, go to
EDIT MODE
and use either of these::x
SHIFT ZZ
-
To exit without making any changes, go to
EDIT MODE
and enter::q
-
To exit without saving, go to
EDIT MODE
and write::q!
-
To display number lines, go to
EDIT MODE
and write::set nu
-
Move left one character -->
h
. -
Move down one character -->
j
. -
Move up one character -->
k
. -
Move right one character -->
l
. -
Move forward one word -->
w
. -
Move to the start of the word -->
b
. -
Move to the end of the word -->
e
. -
Move back one sentence -->
(
. -
Move forward one sentence -->
)
. -
Move back one paragraph -->
{
. -
Move forward one paragraph -->
}
. -
Move to the beginning of the line -->
^
. -
Move to the end of the line -->
$
. -
Move to the nth line -->
<n>G
. -
Move to the last line -->
G
. -
Move to the first line -->
gg
. -
Move to the matching bracket -->
%
.
-
At the cursor -->
i
. -
After the cursor -->
a
. -
Before the current line -->
I
. -
After the current line -->
A
. -
Insert a new line after the current line -->
o
. -
Insert a new line before the current line -->
O
. -
Ovewrite the whold current line -->
C
. -
Exit Insert mode -->
ESC
.
-
Delete a single character -->
x
. -
Delete the rest of the line -->
D
. -
Delete the entire current line -->
dd
. -
Delete the next n words -->
ndw
. -
Delete the next n lines -->
ndd
. -
Delete from line x through to line y -->
:x,yd
.
-
Paste the clipboard contents -->
p
. -
Yank (copy) a line -->
yy
. -
Yank a word -->
yw
. -
Yank to the end of the line -->
y$
.
-
Search for pattern -->
/pattern
. -
Find the next occurrence of pattern (after using the previous command) -->
n
. -
Replace every occurrence of "pattern" with "replace" -->
:%s/pattern/replace/g
.