How Vim stole my heart

I think it is clear from the name that today we will talk about Vim! What it is? Why do you need it? How to use it?

Many who read my past could exclaim:

Indeed, such a practice can be considered unnecessary. To my deepest regret, and now there are people who think the same way. For those who do not know, I will explain: Vim is an old-fashioned text editor that works in the terminal and has a non-standard approach to editing and typing.

A fair question arises: “Why use the old program in 2018, and even without a graphical interface?” The answer is simple - it is convenient. I agree, it can be said absolutely about any editor, but still this case is very unusual.

To begin with, no, Vim is not old - he is only 27 years old. He is the heir to the classic editor Vi. It is better adapted to modern systems and has a wider range of possibilities. In other words, its name (Vi Improved) fully justifies. I also want to note that there is an even newer implementation of the same ideas - neovim.

What is the difference?

If you look at Youtube different videos on this topic, they mostly talk about the metaphysical component of the issue. That is about the difference in ideologies, ways of development of projects and the like. There are no fundamental differences for the end user. However, two points can be clarified: some plugins are easier to install in neovim, in the appendage to the separation of the user interface from the program kernel itself. About the second now I will explain more.

I think there are people among you (and cats) who always answer something like this to the proposal to switch to another editor:

Well, neovim is in a hurry to help! Thanks to him, now in many modern IDE and “programmer notebooks” there is a Vim functionality emulator. Thus, you can continue to use your favorite Sublime Text or CLion with all your plugins, at the same time significantly increasing your productivity in terms of writing code, and starting to get more pleasure from it (more on that later). It is also a good way to increase the CSW, because “real hackers use either Vim or Emacs”.

“Well, I decided to try to learn some vintage editor, but why exactly Vim, and not at least the same Emacs?” Well, this is an ambiguous question. Emacs is a more powerful solution that can do everything (you can even play snake in it). However, this strength of him is also his weakness. It is too extensive and complex, which translates into a higher complexity of development and demands on the gland. The last argument may now sound silly, because it is also a console editor, but in a number of tasks (such as remote connection via SSH) this moment may be critical.

(Emacs users after these lines)

Well, we figured out what Vim is, but it remains to be understood why and how to use it.

“Why did Vim like it so much that everyone adds it wherever possible and even where it is impossible?” (By the way, he also has it in Emacs. It seems to me more and more that it is easier to list things that are not there, but this is off topic.) The answer to this question is simple - his philosophy.

You can’t just go to VIM and start typing. For this there is a separate mode - "Insert mode". When you start the program, you get into the normal mode, in which you are given the opportunity to type commands for editing text and switch between different modes of operation of this editor. “But this is inconvenient! I just want to type the text! ”Technically, a typewriter is suitable for this task, but I will answer without sarcasm. If the majority of editors focus on writing code, then Vim shifts it to editing the text and does it in its own way.

(Actually, this picture has a deep connotation. If you have a moment, read about the Persona series of Japanese RPGs.)

The most important thing to understand when learning Vim commands is that they are mostly not separate. This, consider the whole language, where they are divided into verbs, nouns and adjectives (modifiers). Actually, despite the fact that each team is a single character, each of them has an analogue of the word in English, and their sequence can be translated into a full sentence!

Let's look at a couple of examples, but first hold another picture (this time with something useful):

1). d2w
==> Delete two words.

2). AMew<Esc>
==> “Mew” and “Return to the normal mode”.

3). f(ci(Pakahontas<Esc>
==> Find out what they need to be and what they need to return to normal mode.

Do you see? Absolutely nothing complicated! Of course, such an approach requires habituation and constant practice, since it is simply impossible to learn all the combinations - you have to feel them. I do not write code in Vim because it is typed faster in it (I type so slowly, as you can see, and I do not know how to blindly), but because it is more natural. Instead of a heap, ctrl, shift or alt (there are commands with them, but they are few) a very clear and, most importantly, humane editing language.

(Suddenly, isn't it?)

But before we finish, I want to insert a few comments:

I.Despite the fact that in Vim you can use the arrows and the mouse (the second is configured in the file "~ / .vimrc"), it is strictly not recommended. There is a sea of ​​more interesting commands for moving the cursor through the text (and the screen), only they are no longer as intuitive as editing commands and they will have to be crammed.

(It's hacking time!)

II. In Vim, as in many other editors, there is a command mode that is invoked when you press the ':' key. The '!' it has a dual meaning:

a) If it stands immediately after ':', then a full command for the terminal can follow after it. Although some of them are duplicated as commands of the editor itself, this can be useful, for example, to invoke the compiler.

b)If it comes after the Vim command, then it will execute it without saving changes to the file. By the way, one bug (or, if you wish, a feature) is connected with this - if you did something with the text, then even if you return it to its original state, the editor will not close, if you do not save it or specify '!'.

(Have you already felt how Vim cares about your data?)

III. Different editor and plugin settings can be changed in the above "~ / .vimrc". There are settings for every taste and color, only they are not in the file itself. By default it is empty. In order to find the parameters you need, use the command ": help". You can then add the name of a specific component or plug-in to go directly to the information of interest to you. But, of course, the Internet in this regard will be more comfortable.

There are several commands in Vim (for example, 'q') that are designed to be defined (in "~ / .vimrc") by the user. However, if you try to ask them the value directly, then they will be triggered with a delay, since they expect the second team after themselves (that’s what they should be determined). If you need a one-button command, I recommend that you use 's', since its functionality is almost the same as 'c'. “Substitute” can be replaced, so to speak.

V. The command '.' It has incredible power in this editor. She is able to repeat the previous command (or the whole sentence of them). In principle, if you do not want to write a macro, then it is an excellent way to fill the code with “chebureks”:

VI.Vim reminds me of the old 48 kilobyte ZX Spectrum computers. They also had one-button commands, but they were just for the Basic programming language. Thus, the developers tried to reduce the amount of RAM needed for the program to work.

As a teaching material, I recommend the program vimtutor. Technically, it just opens a file with a short tutorial in Vim, but this approach allows you to practice in parallel with the study of the theoretical part. And then practice, practice and, once again, practice!

Well, actually, everything that I wanted to say about Vim. Honestly, I am delighted with this editor. His philosophy is very infectious and is similar to the Unix system as a whole (everything is simple, clear and logical, but requires getting used to and memorizing). Therefore, if you are looking for a good text editor or you want to get a new text editing experience, then you will not find a better place.

I wish you happiness, health, and so that KDE does not fall!

1) По теме:
а) Собственно, vimtutor
б) Картинка с клавиатурой была взята с сайта viemu
в) Также мною был прочитан викиучебник на эту тему
2) Не по теме:
а) Про серию Persona на Youtube есть множество видео с их подробным анализом. Наверное, наибольшую ценность представляют ролики с какала Filinov's Place, но автор пока остановился на второй второй части (это не описка).
б) Про Spectrum недавно записал хорошее видео Дмитрий Моисеев
в) Автор рисунка с моей аватарки — Fluff-Kevlar

Also popular now: