Basics of Vim
I just put this here so I can for future reference. Of course, there are many cheatsheets and guides on how to use vim. This is just my personal cheatsheets. I am not planning on adding every command, only just some useful ones.
If you find any mistakes here, please let me know.
Additional Reference
Start
Vim has basically four modes:
- Normal Mode (Command Mode) - the default mode.
- Command Line Mode - Play around with commands
- Insert Mode - for editing the contents of the file
- Visual Mode - for selecting the text.
How to enter each modes?
- Press
Escto enter normal mode. - Press
ito enter insert mode. - Press
vfor visual mode. - Press
:to enter command line mode.
Saving and Quitting
Enter command mode
- Use
:wto save the file - Use
wqto save and quit - Use
q!to exit the file without saving changes made to the file - Use
qif no changes were made.
Cursor Movements
h- to move leftl- to move rightj- move cursor downk- move cursor upG- to move to the last line$- to move to the end of a line
More commands for insert mode
o- insert new line after the current lineO- insert line before the current linea- insert after cursori- insert before cursorA- insert at end of lineI- insert at beginning of line
Undo Redo
u- UndoCtrl+R- for redo
Set line numbers or relative line numbers
set number- to display line numbersset relativenumber- to display relative line number