Editor vi: commands, instructions, settings

Computers of the new generation are built as one on the basis of operating systems with a graphical interface. Today, not everyone even remembers that some 40 years ago, all control was carried out using special text commands, and working with a computer resembled one-way chatting. And despite the enormous changes in the world of electronics, there are still many admirers of the command line and products controlled exclusively by text commands. For example, the vi editor, which is rightfully considered one of the most convenient and flexible typing tools to this day. In the material below, we will examine in more detail what constitutes vi. Instructions for the editor, basic commands and features - read all about this below.

vi, team editor

What is vi?

At its core, vi is nothing more than a classic text editor, of which there were many from the beginning of the 70s to the end of the 90s. Specifically, this yl was developed back in 1976. The idea of ​​creating a new simplified text editor came to mind of Bill Joy, who at that time used another popular product - ed. According to Joey and his colleagues, ed was too complex and “mere mortals” could not fully master it. For this reason, George Coloris created his own text editor, which was ironically called the “editor for mere mortals,” and only then Bill modified it and brought it to the modern look that exists to this day.

System requirements

There are no prerequisites for mastering the command line and text editors like vi. You can start from scratch on any platform, whether it be UNIX-like systems (and “forks” from them) or Linux-based distributions. In each of them you can install vi in ​​one form or another. The vi editor for Windows also exists.

Customer options

Before you start working with vi, you need to choose the right client. Of course, you can use the original editor, but it will be limited in capabilities, and it will look too confusing, so you should pay attention to the following applications:

  • Vim is a modified version of the classic editor. The main feature of the program is the ability to install custom extensions, such as syntax highlighting, Unicode support, macro support, saving individual sessions, and much more. There is also a GUI version called GVim.
  • Elvis is one of the first vi clones written in the C programming language and available on all platforms at once. This is a full-screen editor that supports Windows and syntax highlighting.
  • Vile - an attempt to combine the best of two popular text editors. Among users of text editors Emacs and vi, there is an unspoken hostility. The ville developers tried to combine the key features of both programs in order to provide users with a universal tool for working with text.
  • Nvi is a classic vi-based editor recompiled specifically for FreeBSD systems.
  • Viper is not even a separate client, but just a plugin for the popular Emacs text editor, which allows you to emulate vi text editor commands.

team vi editor

Getting started with vi

Most likely, you don’t even have to download anything to work with the editor. Most Linux distributions come with vi included. Actually, to start, you only need to enter the appropriate command and specify the file that should be opened. If you want to open the file in vim, then you need to write - “vim * file name * .txt”. Immediately after this, a document will appear before you. To open it in the graphical interface, you need to replace the command with - “gvim * file name * .txt”. Initially, you will enter the command mode. The vi editor implies working in two modes: edit mode and command mode. The first serves to enter text, and the second to navigate and execute functions like saving. Let's start with command mode and navigation.

Navigation

To get started, you should familiarize yourself with the vi editor commands that allow you to move the cursor in the document. Basically, the keys h, j, k, l are used, which are responsible for moving left, down, up and right, respectively. In principle, modern versions of vi, including vim and graphical forks, support the work with arrows, but if you force yourself to use the classic version, you will get used to it and understand that it is much faster and more convenient. The only feature that can cause bewilderment is the inability to move to the top line with h and l, the j and k buttons are always used to move up and down. To move to the beginning or end of a line, use the 0 and $ keys. Use the keyboard shortcuts Ctrl + F and Ctrl + B to move between pages.

To move between words, use the keys w, e, b. To instantly move to the first character of the next word, press w. To move to the last character of the next word, press E. To place the first character of the previous word, press b. There is also a small snag. The fact is that the editor divides complex words by spaces and dashes into separate words. This means that the expression - night-drive will be considered three different words. In order not to waste time jumping over the dash, you can use commands with capital letters, that is, W together w or B together b.

vi text editor, commands

For more impressive jumps, parentheses () and {} are used. The former help you navigate between sentences, and the others between whole paragraphs.

The most convenient way to navigate is to navigate through the lines and keywords. In order to move the cursor to a specific line, you must enter the line number and G (there must be a capital G). To move to a specific word, you need to start the search with the / symbol. For example, if you want to find the word anaphora, type / anaphora and press Enter. To move between search words, use the n and N.

Editing and Saving

First, find out how to exit the vi editor. This can be done using the command: q, which simply closes the program without any changes. It is worth noting that closing the program will not work if any changes have been made to the document. This is a kind of protection against information loss, therefore, before leaving, you always need to save the entered data. Saving in vi is done using the command: w. Teams can be combined. For example, entering: wq, you simultaneously save the data and close the program. But that is not all. If you want to save the changed document in a new file, then you need to use the vi editor's command “Save to file”, which is implemented by entering: w * filename * .txt.

Now let's talk about “simple” editing, which is tied to similar commands, without changing the content of documents. For example, to delete a character, use the x key, and to join two lines to each other, use the J key. To delete an entire line, double-click the d key. You can replace characters with the r key.

vi command editor, save to file

Any of the commands described above can be duplicated (or repeated several more times) using the key. (point). So, for example, you can delete four lines at once by entering dd ....

These commands can be combined. We already know that with the help of the bracket) you can move to the end of the line, and with the help of the bracket} you can jump to the end of the paragraph. By using the d key along with them, you can delete entire lines and paragraphs without wasting time.

Knowing so many vi editor commands to delete text, you need to find out how to restore everything deleted (you never know). To do this, use the u key, which allows you to take a step back, regardless of what action was performed before (if, of course, this is not closing the program).

Edit Mode

Since you have familiarized yourself with the commands for managing a text editor, it's time to move on to its immediate task - entering text. The text input process itself, of course, is no different from that in any other editor, but it is important to always remember that you constantly have to switch between editing and command modes. To switch to edit mode, press the i or a key (only the cursor position in the text will depend on this). After that, you can immediately start dialing. All text will be entered in one line until you use the o key, which creates a new line, or the cc command, which replaces the current line with new text. To return to command mode, use the Esc key.

vi editor, instruction

Visual mode, copy and paste

Using text editors, we often resort to the function of copying and pasting text. We are used to the hot keys Ctrl + C and Ctrl + V in modern operating systems, so working in vi may seem complicated. In fact, you just need to go into visual mode, after which, using the already studied commands, select and copy the desired text. Copying in the vi editor (as well as pasting) works only in the special visual mode (activated by the v key). In visual mode, part of the text in the document is highlighted. The highlighted area can be changed using the navigation keys and their combinations. Then, after the desired area is selected, just press y to copy the text or d to cut it (delete from the selected area). Inserting text is just as easy - move the cursor to the desired area and press P. The text instantly appears in the area behind the cursor.

Difficult teams

Complex teams mean combined teams. They have already been discussed above, but it is worth focusing on them again, because thanks to the right combinations you can achieve maximum performance and convenience.

vi editor, save

You can also use numbers with some movement commands. For example, if you want to move not by one word, but immediately by 6, then instead of pressing w six times, you can simply enter 6w. Two numbers can be combined with numbers at once. For example, to delete several words at once, you can use the d5w command, which removes 5 words at once. Accordingly, combinations with parentheses will delete lines, paragraphs, and so on.

Text Replacement

Among the additional features, it is worth highlighting the ability to replace entire pieces of text, as well as all matching pieces in a whole document. This is a rather useful option, especially when it comes to program code or filling out large questionnaires with duplicate data. Imagine that there is an explanation expression in the selected line of text, but we want to change it to another one, for example giving food for thought. In this case, the command will look like this -: s / explanation / giving food for thought /. To replace all mentions of explanation in a document, you can slightly complicate the command, then it will look like this:% s / explanation / giving food for thought / g.

vi editor for windows

Instead of a conclusion

So now you understand how to manage the vi editor. Know all the basic commands how to change and edit text. We got acquainted with useful commands and features. The ideal time has come to try it all in practice. Despite its slightly repulsive appearance and high entry threshold, vi, after a short practice, may turn out to be the most convenient tool for you to work with. The main thing is not to panic, to write down all the learned commands, scripts and repeat them all in practice, in order to bring the newly acquired skills to automatism.


All Articles