vi/vim
There are a few modes: insert, normal and command mode.
Normal mode (navigation)
Press the esc
button from any other mode. This is the default mode.
Insert mode (typing & editing)
Press i
from the normal mode. This mode allows us to directly insert and edit text β just like a normal text editor.
Command mode (executing commands)
Press :
from the normal mode. This mode allows us to run several commands without leaving the editor. One feature I really appreciate is the ability to run shell commands β see below for more details.
Useful commands
Save (write) file
:w
Quit
:q
Combine write + quit
:wq
Quit without saving
:q!
Execute shell commands
:!
:! ls
Note: The symbol %
represents the current filename without any extensions
Examples
Eg. Compile and execute a C program file test.c
(that is currently opened)
:! gcc test.c -o test && ./test
:! gcc %.c -o % && ./%
Eg. Execute a Python program file test.py
(that is currently opened)
:! python3 test.py
:! python3 %.py
Eg. Change permissions and execute a .sh
(shell) script test.sh
:! ls -l
:! chmod +x test.sh
:! ./%
Last updated