ComputersSoftware

The vi editor: commands, instruction, configuration

Computers of the new generation are all built on the basis of operating systems with a graphical interface. Today, not everyone remembers that some 40 years ago, all management was performed using special text commands, and working with a computer resembled one-way chatting. And despite the huge changes in the world of electronics, there are a lot of fans of the command line and products managed exclusively with the help of text commands. For example, the vi editor, which is rightly considered one of the most convenient and flexible tools for typing texts to this day. In the following material, we will consider in more detail what vi is. Instructions to the editor, the basic commands and possibilities - about all this read below.

What is vi?

In its essence, vi is nothing more than a classic text editor, which was a lot in the period from the early 70's to the late 90's. Specifically, this was developed in 1976. The idea to create a new simplified text editor came to mind Bill Joy, who at that time used another popular product - ed. According to Joey and his colleagues, ed was too complicated and "mere mortals" could not master it fully. 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 led to the modern look that exists to this day.

System requirements

There are no preliminary requirements for mastering the command line and text editors like vi. You can start from scratch and on any platform, whether it's UNIX-like systems (and "forks" from them) or Linux 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 must select the right client. Of course, you can use the original editor, but it will be limited in capabilities, and it looks 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, individual session saving and much more. There is also a version with a graphical interface called GVim.
  • Elvis is one of the first clones of vi, 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 is an attempt to combine the best of two popular text editors. Among the users of the text editors Emacs and vi there is an unspoken enmity. The developers of ville 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, it's just a plug-in for the popular text editor Emacs, which allows you to emulate the commands of the text editor vi.

Getting started with vi

Most likely, to work with the editor does not even have to download anything. Most Linux distributions are bundled with vi. Actually, you just need to enter the appropriate command to start and specify the file that should be opened. If you want to open a file in vim, you need to write - "vim * filename * .txt". Right after that, a document will appear before you. To open it in the GUI, you need to replace the command with - "gvim * filename * .txt". Initially you will enter command mode. The vi editor assumes working in two modes: edit mode and command mode. The first is for text input, and the second is for navigating and executing functions like save. Let's start with command mode and navigation.

Navigation

First of all, you should familiarize yourself with the commands of the vi editor that allow you to move the cursor in the document. Basically, the keys h, j, k, l, which are responsible for moving left, down, up and right respectively, are used. In principle, in modern versions of vi, including vim and graphical "forks", work with arrows is supported, but, forcing yourself to use the classic version, you will eventually get used to and realize that it is so much faster and more convenient. The only feature that can cause confusion - the lack of the ability to move to the top line by h and l, always use the j and k buttons to move up and down. To move to the beginning or end of a line, use the 0 and $ keys. To move between pages, use the keyboard shortcuts Ctrl + F and Ctrl + B.

To move between words use the keys w, e, b. In order 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. Here, too, there is a small snag. The matter is that the difficult words the editor divides on blanks and a dash on separate words. This means that the expression "night-drive" will be considered three different words. To avoid wasting time to jump through a dash, you can use commands with large letters, that is W together w or B together b.

For more impressive jumps, brackets () and {} are used. The first help to move between sentences, and others between whole paragraphs.

The most convenient way to move is to move through lines and keywords. To move the cursor to a specific line, you must enter the line number and G (it should be the uppercase G). To move to a particular word, you need to start the search with the / character. For example, if you want to find the word anaphora, type / anaphora and press Enter. To move between search words, use the keys n and N.

Editing and saving

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

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

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

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

Knowing so many commands of the vi editor to delete text, you need to learn how to restore everything remotely (is it not enough that). To do this, use the u key, which allows you to step back, regardless of what action was taken before (unless, of course, this is not closing the program).

Edit mode

Since you've read the commands for managing a text editor, it's time to move on to its immediate task of entering text. The process of entering text, of course, does not differ from that in any other editor, but it's always important to remember that you constantly have to switch between edit modes and commands. To enter edit mode, press the i or a key (this will only affect the position of the cursor in the text). After that, you can immediately begin to dial. The whole text will be entered in one line, until you use the o key that creates a new line, or the cc command, which will replace the current line with new text. To return to the command mode, use the Esc key.

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 the work in vi can seem complicated. In fact, you just need to go into the visual mode, after which you can select and copy the desired text with the help of the commands already studied. Copying in the vi editor (like insert) works only in a special visual mode (activated with the v key). In the visual mode, part of the text in the document is highlighted. The illuminated area can be changed by 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 selection). Paste 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.

Complex commands

Under complex commands, there are teams combined. They have already been discussed above, but they should be emphasized once again, because thanks to the right combinations, you can achieve maximum productivity and convenience.

Also you can use numbers with some move commands. For example, if you want to move not one word, but immediately to 6, then instead of six times pressing w, you can simply enter 6w. With numbers, you can combine two teams 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 brackets will delete strings, paragraphs, and so on.

Text replacement

Of the additional features it is worth highlighting the ability to replace whole pieces of text, as well as all matching pieces of the whole document. This is a useful option, especially when it comes to programming code or filling out large questionnaires with duplicate data. Imagine that there is an explanation in the selected line of the explanation, but we want to change it to another, 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 the explanation in the document, you can slightly complicate the command, then it will look like this::% s / explanation / giving food for thought / g.

Instead of concluding

So now you understand how to manage the vi editor. You know all the basic commands, how to edit and edit text. Acquainted with useful commands and opportunities. It is the ideal time to try all this in practice. Despite its slightly repulsive appearance and high entry threshold, vi after a short practice may be the most convenient tool for you to work with. The main thing is not to panic, write down all the learned commands, scripts and repeat them all in practice, in order to bring the newly acquired skills to automatism.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.delachieve.com. Theme powered by WordPress.