Insert, Search, Edit
You can enter insert mode from normal mode by pressing the key
i text you type will be inserted
You can enter visual mode from normal mode by pressing the key
v starts a visual selection
There are several more ways to enter insert mode, depending on where you want to insert the text:
i insert at current location
a insert after current location (append)
I insert AT START of current line
A insert AFTER END of current line
o insert line below current line (open)
O insert line ABOVE current line
s delete character under cursor and start inserting in its place (substitute text)
S delete all text on line and start inserting in its place (substitute line)
cw delete to the end of current word and start inserting in its place (any movement command can be substituted for w
)
cc same as S (change line)
C delete from the cursor to the end of line and start inserting at the cursor position
For example, starting in normal mode, if you press A then type “hello” and press Esc, you will append “hello” to the end of the current line
If you move to another line and press . you will append “hello” to that line as well (. repeats the last operation).
If you had used I (instead of A), the “hello” would have been inserted at the start of the line, and pressing . would repeat that operation.
Saving and quitting
Press Esc to enter normal mode, save the current file by entering :w (which always writes the file even if it has not changed), or :update (which only writes the file if it has changed).
Save the editing an existing file with another file name with :w filename or :saveas filename, for example, :w myfile.txt.
Quit Vim Press Esc then :q. Or the saving and quitting can be combined into one operation with :wq or :x.
Discard any changes, Press Esc then enter :q!
:wa write all changed files (save all changes)
:xa exit all (save all changes and close Vim)
:qa quit all (close Vim, but not if there are unsaved changes)
:qa! quit all (close Vim without saving—discard any changes)