In this tutorial I will share some vim basics. Vim is a powerful text editor used in CLI (command line interface). Because gnu/linux uses a lot of configuration files which are all in clear text format, you’ll often need to edit them and vim (in short vi) is a great tool to use.
vim (vi) has a particular working method. Indeed there are to main mods : command and other mods, so if you get familier with some basics then it will be a very good starting point.
The command mod lets you select the mod you want to enter to, save, quit, copy, paste and that kind of things but you can’t edit the file in this mod.
There are several other mods. In this article I’ll only speak about those I often use.
After opening a new OR existing file in vim editor with vim you can try mods listed here.
Insert mod : lets you insert text in a document. Shotcurt : “i” (insert where the cursor is) or “o” (insert at the beginning of the following line).
Visual mod : permits to select the text like you would do with a mouse but using the keyboard instead of the mouse. Useful to copy several lines for example. Shotcurt : V
Let’s now speak about the command mod.
A command begins with the symbol “:”.
When you are in another mod you can use the escape key (sometimes you’ll need to hit it twice) to come back to command mod at any time.
save : :w
save and exit : :wq
exit : :q
force : ! (example :w! :q!)
vertical split : open a document and then type :vsplit /path-to-document/document and this will open the specified document and split the screen so you can see both documents.
copy : y
copy a line : yy
paste : p
cut : d
cut a line : dd
I repeat these are very basic commands for vim, but they are very useful, and I hope this will help you configuring your Linux.