Introduction to Vi
Despite its very limited ergonomics, Vi i is one of the most popular text editors texte under Unix type systems (with Emacs and pico). Under Linux, there is a free version of Vi called Vim (Vi Improved). Vi (pronounced vee-eye) is an editor that is fully in text mode, which means that all actions are carried out with the help of text commands. This editor, although it may appear of little practical use at first, is very powerful and can be very helpful in case the graphical interface malfunctions.
The syntax to launch Vi is as follows:
Once the file is open, you can move around by using cursors or the keys h, j, k and l (in case the keyboard does not have any arrow cursors).
Vi has three operating modes:
- Regular mode: This is the mode you enter whenever you open a file. This mode allows typing commands
- Insertion mode: This mode makes it possible to insert characters you capture inside of the document. To switch to insertion mode, just press the key Insert on your keyboard or, by default, the key i
- Replacement mode: This mode allows you to replace existing text by the text you capture. Just hit r again to go to replacement mode and hit the key Esc to return to regular mode
||Quit the editor (without saving)
||Forces the editor to quit without saving (even if changes were made to the document)
||Saves the document and quits the editor
||Saves the document under the specified name
||Deletes the character that is currently under cursor
||Deletes the line that is currently under cursor
||Deletes x lines starting with the one currently under the cursor
||Deletes n characters starting with the one currently under the cursor
||Indents x lines to the right starting with the one currently under the cursor
||Indents x lines to the left starting with the one currently under the cursor
Searching and replacing
To search for a word in a document, in regular mode, just type / followed by the chain of characters to be searched for and confirm by hitting the Enter key. Use the n key to go from occurrence to occurrence.
To replace a chain of characters by another on a line, you will find a very powerful command in Vi by using the regular expressions. Its syntax is as follows:
IThe replacement can be made throughout the entire document with the following syntax:
Copy-paste and cut-paste
In Vi, it is possible to copy-paste a selection of lines. To do so, just type in the following command to copy n lines:
For example, the following command will copy 16 lines onto the clipboard:
To past the selection, just type the letter p
Cutting-pasting n lines is similar by using the command:
Latest update on October 16, 2008 at 09:43 AM by Jeff.