Using VIM: Basic Tutorial.

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 :

Vim (From English I saw IMproved) is an improved version of the text editor vi, present in all systems UNIX.

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.


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

21 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   dwarf said

    I would use Gvim, although I did not see the syntax highlighting and it would have been good if you put images of some text in HTML to see how all that is. I'm going to get to work with Vim and then I do one of those deep analyzes like I did with Gedit… give me a week and I have it.

    1.    Abel said

      If you want to see how syntax highlighting works well, I leave you a couple of examples.
      ompldr.org/vZTRlYg
      ompldr.org/vZDd3cw

      And in a link below a lot of schemes to make it more visually pleasing. xP

      Greetings.

  2.   Slayer said

    The vim tutorial is very good, hopefully one will be made later, a little more advanced or some more tricks, which can be done with this tool;),
    for the moment to get into this world of vim now

  3.   ren434 said

    At the moment I am stuck with emacs, which lately has me more and more trapped, on the other hand vim makes it very difficult for me to move between the text.

    PS: Congratulations! They are first in the Ranking.

    1.    msx said

      +1

      We men use Emacs, you know!
      When I started reading "I never thought I was going to say this, but I'm incredibly liking the best editor for the terminal on GNU / Linux ..." I thought: great, he discovered Emacs!
      Instead it turns out that the guy goes out with fagots 😛 the things that one finds on the net!

      1.    elav <° Linux said

        Ohh that macho. I guess then you use LFS, because using a distro with everything chewed up I suppose it is also a fag right?

        1.    pandev92 said

          Man emacs seems quite easier than vim but for color tastes.

  4.   Dav said

    vimtutor is a very good interactive tutorial, it is designed to be completed in 25-30 minutes. highly recommended!
    apt-get install vimtutor
    vimtutor

    1.    dwarf said

      That sure works for me, I have to work on that

    2.    elav <° Linux said

      Yes, Vimtutor is actually great ...

  5.   wheezy said

    Play this game and that's when you will not stop using vim and you will learn to use it foolishly, really, you are going to practice a lot with this game the most basic things about vim such as knowing how to move quite quickly.

    http://vim-adventures.com/

  6.   Mauritius said

    I'm not a developer, so what I need to do: edit a .conf or put my hands in a pkbuild from time to time, with NANO it is enough and I have plenty. Once for testing I opened a file in VIM and I didn't even know how to get out of there.

  7.   Abel said

    Pretty basic for those who start with vim, even I thought it was a monster but like everything, it's just a matter of habit. xP

    I leave a lot of schemes for those who want to try.
    http://code.google.com/p/vimcolorschemetest/

    Greetings.

  8.   proper said

    @elav, I leave you my vimrc so you can use some config that works for you 😉
    http://paste.desdelinux.net/4465

    1.    elav <° Linux said

      Thank you

  9.   anubis said

    I'm getting a taste for the best editor that exists for the terminal in GNU / Linux

    You like to cause flames, huh? This is probably the oldest flame 😛

    PS: VI Rocks!

  10.   Charly said

    Excellent tutorial! thank you very much 😀

  11.   esme said

    very interesting: 3

  12.   JSequeiros said

    Something basic is always good.

  13.   Rene, from Mexico, can. said

    It is good to know a little about everything, in case you need it one day, The wise man will always value the sacrifice of his fellow man.

  14.   William said

    Excellent tutorial but I'm new to this and I don't know how to add the brigthscript editor to gvim https://github.com/chooh/brightscript.vim.git Could you help me