I never thought I was going to say this, but I'm incredibly liking the best editor out there for the terminal in GNU / Linux: Vim.
Quoting Wikipedia :
His actor, Bram moolenaar, presented the first version in 1991, date from which it has undergone many improvements. The main characteristic of both Vim and Vi is that they have different modes that can be switched between to perform certain operations, which differentiates them from most common editors, which have only one mode in which orders are entered using key combinations or graphical interfaces.
I am one of those who thought that this was an editor for "octopuses" or people with more than 10 fingers, because the simple fact of having so many keyboard shortcuts made me think that Vim it was the "monster" of console editors. The truth is that since yesterday I have been learning to use it (even with very basic things) but I'm getting used to it, and the worst (or best of all) it's that I'm liking it too much.
I have always been comfortable with how dwarf, but it is true that this editor is too basic. When we have a graphical environment, the cursor can be used to copy / paste, but when we are in a TTY things change. That is the first advantage that I find VIM. Other features that I like are:
- Selection of text in columns.
- Syntax highlighting.
- Highlighting of parentheses, brackets and braces (so it is ideal for programming).
- Extremely powerful, even when the file we are editing is interrupted, it allows us to recover it later.
- Here you can see many more ...
The only text editor in console (of the ones I know) that "approaches" to Vim es MCEdit, MC's text editor. But notice the quotes in the sentence above. VIM even has an editor in GTK. But the idea of this post is not to sell you or encourage you to use Vim, it is simply a way of telling you that it is easier to use than it really appears.
Basic tutorial on using VIM
I was thinking of leaving you a series of keyboard shortcuts, but I think it would be much more practical if I showed you how it works by means of an example. The first thing we will do is install Vim if we have not already done it, or if it does not come by default in our favorite distribution. Once installed, we open a terminal and put:
$ vim prueba.txt
We will see something like this:
Now we press the key I or the key Insertion to switch from command mode to edit mode and start typing. We write anything, if possible, that has more than two lines. I for example put:
Now, we press the key ESC To exit edit mode, we move to the beginning of the document with the keyboard arrows and press the key V. You will notice that below says now VISUAL. With the down arrow we are marking all the text that we write. When we have everything selected, we press the key Y. Once this is done, you will see that below it indicates the number of lines copied.
Now we move a little lower and press the key P. Each time we press it, the same text will be pasted. If instead of the key Y we press the key X, the text we selected will be cut off. We can paste it back with the key P.
Now we are going to save the test document. We press ESC if we are in edit mode and write :w, that is, two points and a W. What this does is write or save what we are doing. If we later write :q we will exit the editor. If what we want is to save and close, we write 😡.
Now one last trick. Suppose that we accidentally close the terminal and lose the document. What we have to do is rewrite:
$ vim prueba.txt
and we will get something like this:
If you look at the end we have a series of options. In this case we press the key R to retrieve the previous document, then it will ask us to press ENTER And voila, we can continue where we left off. Now, if by chance we hit the key E (edit anyway) we can also retrieve the document by typing : recover, and we will get something like this:
In this case my option is to write number 1 and voila, our work is recovered again.
If you want to use Vim easier, then you could install GVIM, which is the same using Gtk libraries for the use of Menus and other options that facilitate the user's work.
There is even an extension for Firefox call Vimperator, that allows us to handle the browser as if Vim it will be 😀
And this far Howto, any suggestion or information is welcome so that we can all learn more useful things about Vim.