Skip to main content

VI Text Editor Tutorial


The VI or VIM is a terminal text editor used on many unix/linux systems. It is widely used and very useful.
With little expirience and few learned tricks, It can enhance Your productivity. It has some very interesting features that
can definately help You to write Your code faster. To enter VI, in command line prompt enter "vi" with the name of a file You want to edit. Once VI is lunched, simply press "Esc" to enter in user mode, and press"i" to start inserting text: 


LinuxBox#vi my_file.txt Here's some text for file. (insert mode)

Once done, You can save a file by "Esc" - entering command mode, after which follows command to save/write and quit ":wq!": 

LinuxBox#vi my_file.txt Here's some text for file. :wq!



If just want to quit from VI without saving, use "q!". Ragarding the function You want, VI have large number of commands that can be entered in command mode. 
Command mode can be entered by pressing "Esc" and ":"

Some usefull commands that can be entered in command mode are:

":w" - Write out the current file (save).
":wq!" - Write out the current file and quit.
":q!" - Quit VI without saving changes.
":/string" - Search for a string in a file. 
":s/pattern/to_pattern/g" - Substitutes the specified pattern with the string in the to_pattern. 
(If a 'g' is specified, then all occurences are substituted) 
":nu" - Shows the number of a current line. 
":g/string" - Finds all string ocurences in a file.




Simply by entering "Esc" You enter in user mode.
Some usefull commands that can be entered in user mode for start are: 

"a" - enter insert mode, the characters typed in will be inserted after the current cursor position.
"h" - move the cursor to the left one character position.
"i" - enter insert mode, the characters typed in will be inserted before the current cursor position.
"j" - move the cursor down one line.
"k" - move the cursor up one line.
"l" - move the cursor to the right one character position.
"r" - replace one character under the cursor. Specify count to replace a number of characters.
"u" - undo the last change to the file. Typing u again will re-do the change.
"x" - delete character under the cursor.
"A" - Append at the end of the current line.
"I" - Insert from the beginning of a line.
"dd" - Deletes the line in which cursor is located.
"D" - Deletes the text from the cursos to the right end of a line.
"G" - Goes to the end of a file.
"0" - Goes to the begginging of a file.

LinuxBox#vi my_file.txt Here's some TEXT for file. :/TEXT

Comments

Popular posts from this blog

Cisco three-layer hierarchical model

Because networks can be extremely complicated, with multiple protocols and diverse technologies, Cisco has developed a layered hierarchical model for designing a reliable network infrastructure. This three-layer model helps you design, implement, and maintain a scalable

Access Control Lists (extended)

Access Control List  or  ACL  is a technic of controling network traffic. It is a list of rules with which traffic flow can be manipulated - permitted or denied. By default, traffic flow from the interface with the higher security level (for example "inside" interface) to interface with the lower security level (example "outside" interface) is allowed by default, but the flow of traffic from "outside" to the "inside" interface must be explicitly permited. 

Classes of IP addresses

TCP/IP defines five classes of IP addresses: class A, B, C, D, and E. Each class has a range of valid IP addresses. The value of the first octet determines the class. IP addresses