About Vim said and written more than enough. But most of the materials are either the most initial information, or the advice of experienced professionals. As a result, in order to adapt the editor to solve the tasks facing the user, you have to shovel a bunch of manuals. Before realizing the scale of the work needed, we need a serious incentive to decide on this. And a reasonable question may well arise: why do I need this? Besides the fact that it is interesting to “touch” the editor, about which there is so much talk, there must be something else?
Specifically for me, the stimulus was the difficulty that arose when working with translations. The problem was the following: despite the screen resolution in 1920x1200, it was almost impossible to make both texts appear before my eyes. Yes, and twitching the mouse back and forth, managing the scroll bars, remembering the position of the text fragments, quite uncomfortable. The console text editor, which is controlled by the keyboard, seemed to me a logical solution. It only remained to understand it and from the vast array of information choose only what you need.
Looking ahead, I will say that the information had to be collected in fact bit by bit. The main focus in using Vim as an editor for programmers is that little attention is paid to processing simple text. In the end, with the task, I think, managed to cope.
')
Initial information about the work of the editor.
About command mode, insert mode, text navigation, etc., it is written more than enough. However, all this can be reduced to one team - vimtutuor. This, as the name implies, is a basic Vim tutorial. If your distribution is Ubuntu, you must first install the full version of the editor:
sudo apt-get install vim-full
The only significant, in my opinion, aspect that does not cover the tutorial is to work in visual mode. But here everything is simple: In command mode, press the "v" key, select the necessary piece of text, and then perform the necessary operation with it: whether it is formatting, deleting or copying.
The most important question that should be answered before using Vim for word processing is the transfer of typed text in lines. By default, the editor will write the text in one long line, the boundary of which will be the Enter key.
This is good for editing source code, but completely unacceptable for writing text. There are two solutions here. Use command
:set wrap
This will cause the editor to move to another line when it reaches the edge of the terminal window, but the transition will not set the end-of-line character. Thus, everything that we type before pressing Enter will be one long line. This is not very convenient, since row navigation is a rather important aspect of editing. The solution to this situation is to use the command.
:set tw=80
It will set the string length to 80 characters, which, in my opinion, is optimal.
When the specified value is reached, the editor will move to another line by placing the line end character.
Text formatting
The next question that needed to be answered was how to format the text. The following commands are useful for this:
:ce -
:ri -
:le -
But how to align the text, as they say, "by paragraphs"? That the left and right edge were equal. Help Vim says that you need to use an external program. But there is another solution. We connect the macro (it comes in the standard package):
:source $VIMRUNTIME/macros/justify.vim
After that, the command "_j" in edit mode, you can align the selected text "by paragraphs".
Despite the fact that we have set a fixed width, when editing text, it may happen that one line is longer, or, on the contrary, shorter. This is quite logical - because the line ends with a line break, which can be wiped or shifted to the left. To bring a paragraph to a fixed width, select the text block in visual mode and use the “gq” command.
Spellchecking.
An integral function of a text editor for me is a spell checker. In Vim, this issue is solved as follows:
We download archives with dictionaries. Unzip them to the / tmp / dict folder (without subdirectories inside).
Create a folder
mkdir -p ~/.vim/spell/
Next, we form the dictionary in Vim-format with the command:
:mkspell! ~/.vim/spell/ru /tmp/dict/ru_RU
:mkspell! ~/.vim/spell/ru /tmp/dict/ru_RU
- for Russian
:mkspell! ~/.vim/spell/en /tmp/dict/en_US
:mkspell! ~/.vim/spell/en /tmp/dict/en_US
- for English
It is clear that the dictionary can be of any available language. Moreover, the simultaneous verification of a multilingual document works great! After that, the spell checker can be enabled with the command:
:setlocal spell spelllang=ru_ru,en_us
Work with multiple documents.
To open a new window, use the following commands:
:new
- creates a new document in a new window.
If you want to open an existing document, the best way, in my opinion, is to enter it in command mode.
:Sex
A file manager similarity will open in which you can select the file you want to edit. Moving from window to window is as follows: We press CTRL-w, and then move to the required window using the cursor arrow. Instead of the cursor, you can use the navigation keys - h, j, k, l
After all required documents are opened in one window, it is necessary to arrange them in places, choosing the required size. This is done like this:
CTRL-w, and then the navigation key, only with the -H, J, K, L shifter pressed, respectively.
Having spread the windows, you can adjust their size to your specific needs as follows:
CTRL-W +
CTRL-W -
resize the window vertically;
CTRL-W <
CTRL-W>
resizes the window horizontally.
As a summary.
If the above turned out to be useful for you, and Vim turned out to be suitable for writing and editing texts, it's time to move on to compiling your configuration file. To do this, open the vimrc file in your home directory - and enter the commands that you find useful for everyday use. I have the width of the text, the spell checker, and the use of macrosto align text “by paragraphs.”
In addition, if you are using Unicode, I strongly recommend that you familiarize yourself with the materials on
ru.wikibooks.org/wiki/Vim and write in the configuration file a reassignment of characters. Because the constant switching of the Russian-English layout in command mode is really tiring.
ps At first I wanted to post this topic on a Vim blog. But I decided that his readers were already familiar with the text editor, and such initial information would not be interesting. But for newbies in the world * nix, who heard about the "war" of text editors, the material will be informative and will allow you to more quickly start using the editor for everyday needs.