
- •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.
Practical work № 2
Theme: Editor vi/vim for UNIX-systems
1 Purpose of the work
1.1 The text editor for Unix - systems.
1.2 Get practical skills in the editor vi / vim.
1.3 To study the ability of major features editor.
1.4 Consider the scenario files vi / vim, to practice writing simple scripts.
2 Key princeples
2.1 General
Editor vi - universal full-screen text editor in UNIX. Its versatility means that, first, this editor is available on all UNIX-like operating systems, and, secondly, the fact that the editor works with virtually all types of terminals (ANSI, VT100, VT220, VT320, DEC, etc . etc.). Vim means 'Vi Improved' - enhanced vi. Vim supports syntax highlighting in the program text, and different fonts, common and thickened. Versatility turned somewhat unusual user interface: to manage the editor uses a "normal" keyboard (meaning alphanumeric characters and punctuation marks). Available in many types of terminals function keys are not used. If the keyboard of the terminal has arrow keys, they are used, but, as will be seen below, with some restrictions.
Editor vi / vim often run just the name the file to edit the command line, ie, command vi or vim, if you created the appropriate link:
vim filename
Of course, there are many options, but for now, none of them would be required. You can run vim (but not vi) without any arguments - you start editing an empty buffer, which later can be saved.
By editing in vim understood below listed steps:
1. Downloading a file in the buffer.
2. Making changes to the buffer.
3. Saving the buffer to a file.
2.2 Modes Editor
Text input. In this mode, all keystrokes, is displayed on the terminal screen and stored in the buffer editor.
There is no possibility to carry out operations edit text, except for deleting the last character typed (with the key combination <Control-H>).
Command mode. In this mode, pressing the keys have special functions (cursor movement, removal of parts of the text, and so on), that is, editing functions.
Type commands do not appear on the screen!
Command line mode. Command line mode allows a global operation with the text written in the edited text file, read the new file, exit vi, Tunes editor, pattern matching and perform some editing functions.
The commands are displayed at the bottom of the screen (in the "command" line editor).
Text input
<Return> - creates a blank line and moves the cursor to the beginning.
<Control-H> - deletes the last character (this will not appear on the screen to exit the command mode).
<Control-[> key or <Esc> - Editor in command mode.
When writing, An arrow key does not work.
Teams
i – Insert at cursor;
a – Append after cursor;
A – Append at end of line
R – Overwrite characters from cursor onward.
Moving the cursor
h, j, k, l – Move cursor left/down/up/right;
0 – Move cursor to beginning of line;
$ – Move cursor to end of line;
^ – In the beginning of the current line (ignoring characters brackets);
+ – To the top of the following line;
- – In the beginning of the previous line;
<N> – On the n-th character of the current line;
H – Move cursor to top of page;
M – Move cursor to middle of page;
L – Move cursor to bottom of page;
<N> H – On the n-th row of the screen, starting from the top row;
<N> L – On the n-th row of the screen, starting from the bottom line;
w – Move cursor a word at a time;
b – Move cursor back a word at a time;
) – Move cursor to beginning of next sentence;
( – Move cursor to beginning of current sentence;
} – To the top of the next section (section - is a block of text separated with an empty string);
{ – In the beginning of the previous paragraph;
[[ – In the beginning of the text;
]] – The end of the text;
The buttons also allow the arrow keypad to move around.
Editing
dd - celete line;
d + cursor movement commands - remove the text from the cursor to the new, defined character cursor (Pressing an arrow key is not a command to move the cursor and can not be used in combined teams);
J - a merger of the current line to the next;
u - Undo the last command
. - Repeat the last command
: - Switch to the command line.
Command Line
: q or: q! - Exit the editor without saving changes
: x - exit from the editor to a record if the file has been modified
: w or w filename or w! filename - file entry and return to command mode
: e filename or: e! filename - file download filename
: r filename - add the contents of the file to the edited immediately after the current line
: set nu - to include line numbers
: set nonu - disable line numbers
:! command - UNIX command without leaving the Editor
:/ word - word search for the word in the text
:/ - Repeat word search word hereafter.