- •Practical work № 2
- •1 Purpose of the work
- •2 Key princeples
- •2.1 General
- •2.2 Modes Editor
- •2.3 Blocks, buffers, the editing window. Repeaters
- •2.4 Setting the initialization files vim
- •2.5 Additional Options
- •3 Key question
- •4 Home work
- •5 Lab task
- •6 Requirements for the protocol
- •6.2 Purpose of the work.
2.3 Blocks, buffers, the editing window. Repeaters
Repeaters. And cursor movement commands can be given to repeaters (numbers), for example:
2w - move the cursor to the next word or two
10l - move the cursor to ten characters to the right
d10l - erase ten characters to the right of the cursor
2d10l - erase twenty characters to the right of the cursor
5J - merge the five subsequent lines into one
4. - Repeat the last command four times
Buffers vi
The editor has three types of buffers: Buffer erase (0-9), the unnamed buffer and named buffers (a-z).
In buffers erase erased automatically stored items. The buffer 0 stores recently worn item in buffer 1 - the penultimate, etc.
Add to buffer:
yy - to place the current line into the unnamed buffer
ydvizhenie cursor - add the specified block of text by moving the cursor to the unnamed buffer.
"Ayy - to place the current line into named buffer a
"Ayy - add a row to the contents of the named buffer a
"By10j - to place the next 10 rows in the named buffer b
Paste to buffer:
p - paste the contents of the current position of an unnamed buffer
"Ap - insert into the current position of the contents of the named buffer a
"1p - insert into the current position of the buffer erase one
Because when you copy and paste text fragments we actively use registers, let's discuss them in detail. Vim supports the following registers:
• unnamed register ““;
• 10 numbered registers “0 to “9;
• Register of small removal “-;
• 26 named registers “a to “z or “A to “Z;
• 4 registers, read-only: “:, “., “%, “#;
• register the phrase “=;
• register allocation “* and “+;
• Register “Black Hole” – “_;
• The last search pattern “/.
Unnamed register is used for all the copy or delete, if only as a destination register is not specified "black hole." In the latter case, the removal of fragments is not copied to any of the registers. If you insert the text Unknown register-source, then the source is unnamed register. If the destination register copying specify unnamed register, the entry in the register is "0.
Numbered registers are filled deleted or copied text fragments. In this case "0 contains the last copied fragment if the target was not specified register. Case "1 has recently deleted fragment unless stated another register, and if the remote fragment contains more than one line of text. When you remove fragments smaller than a line, it is copied to the register "-. Each successful removal of fragments from the register "1 is transferred to the register," 2 of "2" 3 and so on. Register is "9 is lost.
Named registers recorded only on direct orders from the user. In this case, if you specify a lower-case letter, the fragment will be overwritten, and if the title, the fragment will be added.
Multi-view editing
Edit multiple files, you can either using the command editor: e filename, or by specifying all the necessary files on the command line when calling the editor (for example: vi file1 file2 file3). In the latter case, you move through the list of files with the following commands:
: n - go to the next file in the
: rew - go back to editing the first file in the list
Named buffers retain their contents in the transition to edit another file.
Basic commands for working with multiple files and windows are presented in Table 2.1.
Table 2.1 – The use of "windows" when editing
Command |
Description |
Mode Normal |
|
:sp |
Divide the current window in two horizontally. As a result, you have two types of the same file. The initial window is divided in two. |
<CTRL> + W S |
|
<CTRL> + W |
|
<CTRL> + S |
|
:vs |
Divide the current window in two vertically. As a result, you have two types of the same file. The initial window is divided in two. |
<CTRL> + W v |
|
<CTRL> + W |
|
<CTRL> + V |
|
:new |
Creates a new window (horizontal separation), which begins editing an empty (new) file. |
<CTRL> + W n |
|
<CTRL> + W |
|
<CTRL> + N |
|
:vne |
Creates a new window (vertical separation), which begins editing an empty (new) file. |
