Bram Moolenaar , the creator of vim, cloned and improved vi and released it in 1991. The name vim came from "vi imitations", later changed to "Vi improved". Gradually it became the most popular text editor among Linux users. In 2019 Stackoverflow developers survey vim was the fourth most popular text editor.
In their last survey, Stackoverflow revealed over 2.1 million people visited the ' How do I exit the Vim editor? ' question on Stack Overflow. So I am writing some top googled vim commands and the general know-how required to use vim.
Out of so many, the most frequently used are "command-line mode", "normal mode" and "insert mode".
You are in normal mode when you open a file. To go back to the "normal mode", press the
To run a command, go to the command-line mode by typing colon
Get into "insert mode" by pressing
i in "normal mode".
Esc key to enter "normal mode" then press colon
: to enter "command-line mode". At the bottom left corner of vim, a colon
: appears. Now you can type any command and press the
Enter key to execute the command.
vim command to open a file
Type vim preceded by file name to open a file in the vim text editor.
vim command to save and exit
Esc to get out of "insert mode". Press colon
: to get into the "command-line mode" and type
wq to write and quit the file. If you have not made any changes to the file, you can exit by
:wqto write and quit
:q!to quit without writing
:xto save and quit (similar to :wq)
:exitsave and exit (similar to :x)
vim command to edit file
i key in "normal mode" to start editing the file. Move around with arrow keys or use these keys:
vim command to go to the end of the file
shift+g to go to the end of the file in vim.
vim command to go to top of file
1G to go to the beginning of the file.
vim command to delete all lines
d to delete. Go into "command-line mode" by pressing
: and type
%d to delete all lines. You can also use range
1,$d. Just like regular expressions
$ sign represents the end of the file.
vim command to show line numbers
In "command-line mode" type,
set numbers or short command
set nu to display line numbers of the file.
vim command to replace string
Type search string followed by the replacement string
vim command to delete lines with pattern
Inside "command-line mode" type,
:help command to check usage documentation. Add a query after
:help to get specific help. Vim comes with a separate tutor program to teach vim usage. Run
vimtutor in the terminal for this 20 minutes practice tutorial. Use the comments section to mention any other essential commands that I have missed.