To go to insert mode: i
To save: [Esc] and zz
To write and quit: [Esc] and :wq
You need to press [Esc
] key followed by the colon (:
) before typing the following commands:
q
Quitq!
Quit without saving changes i.e. discard changesr fileName
Read data from file called fileNamewq
Write and quit (save and exit)w fileName
Write to file called fileName (save as)w! fileName
Overwrite to file called fileName (save as forcefully)
e filename.txt
open filename.txt. This could be a path to filename or just the filename.
h
, j
, k
, l
to move around. Or just use arrow keys.
f
, F
, t
, T
f
Move forward. For example: f
then a
will take you to the next a.
F
Move backward
t
and T
are simliar to f
and F
. The only difference is they place the cursor before the next a instead of exactly on it.
w
, b
, e
w
Move to the beginning of next word
b
Move to the beginning of the previous word
e
Move to the end of current or next word
0
, _
, $
0
Move to the far-left on the current line
_
Move to the first character on the current line
$
Move to the last character on the current line
gg
, G
gg
Top of the file
G
Bottom of the file
{
, }
{
Beginning of Paragraph
}
End of Paragraph
esc
and v
V
to select an entire line, d
to cut it, p
to paste itd
(aka delete) is for cutting and y
(aka yank) is copyingDefult mode. This is the mode for moving around files. You can always get to the normal mode by pressing the [Esc
] key.
This mode is for typing. Press i
to go to insert mode.
This mode is for selecting things. Press v
to go to visual mode.
d
, D
Delete lines
d
Delete
d
then w
Deletes till the end of the word
d
then $
Deletes till the end of the line
d
then 0
Deletes all the way back to the start of the line
D
Deletes the whole line
x
, X
Delete a single character
x
Delete the character under the cursor
X
Delete the character before the cursor
~
Swap the case of the character under the cursor
v
then $
then ~
to change the case of the whole line
.
Repeats the last action you did
u
Undo
ctrl
+r
for Redo
:s
followed by /
, ?
or &
:%s/amazing/awesome
Search this document for amazing and replace it with awesome
:%s/and/\&
Search this document for and and replace it with &. Notice that you need to escape &
:%s
Search this document
:%s/and/but/g
The /g
in the end means change it globally (everywhere in the file), not just the first instance.