The essentials of Vim
The 9 things that you must know when working with the text editor
Linux offers a variety of text editors, and one of the most popular is Vim. The experts in its use prefer it over a standard IDE because it is much more convenient and fast. Personally, I work with it, or with a less feature rich version called Vi, when working on a remote server that I do not have access to with a standard text editor. So this tutorial is essentially a survival guide for those who have to go through with Vi / Vim editors and therefore must learn the bare minimum.
Vim offers endless possibilities for streamlining your work. Here I have summarized the 8 most useful things that you need to know in order to work with Vim.
1. How to open file for editing with Vim?
To open file for editing with Vim you need to type vim and the file name that you want to edit.
$ sudo vim [filename]
2. Vim has 2 modes
Vim has 2 modes: command and insert.
- Use the command mode to navigate the file, perform searches and executing commands.
- Use the insert mode to edit the file.
Every time you open a file with Vim you will find yourself in the command mode. In the command mode you will not be able to edit the file but only navigate within it and run commands.
3. How to navigate the file in the command mode?
In the command mode, you navigate the file with the keyboard arrow keys.
To skip to the end of the file, use the keyboard shortcut: Ctrl + End.
To skip back to the beginning of the file press: Ctrl + Home.
4. How to search the file?
To search the file click a slash followed by the search phrase while in command mode:
Once you finished typing the search term click the Enter key to execute the command.
When working with Vim hit Enter when you want to exectue a command.
5. How to find the next case of the search term?
Once you have found the search term you are looking for, clicking the n key will take you to the next occurence of the term in the file.
6. How to switch to insert mode?
Press the i key to switch to insert mode.
In insert mode you can edit the file, write text, and delete.
If you are not sure what mode you are in then look in the lower left corner of the terminal. If it says INSERT then you are in the insert mode.
7. How switch back to the command mode?
Once you are done editing the file, hit the Esc key to get out of the insert mode and get back to the command mode.
8. How to edit another file?
In command mode:
9. How to save and quit?
Use the commands for saving and quitting when you are in the command mode.
To save the file without quitting just type:
To quit the file without saving:
In order to quit and save:
Vim is a text editor that offers a wealth of options, and if you want to learn more there are many guides floating around the internet and it is always worthwhile to read the documentation.
Recommended for you: