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

Debugging on Cisco ASA

Most of debuging on Cisco ASA can be done with simply entering  "debug"  in front of command for which we want to do debugging. For example if wanted to see/capture icmp traffic from user enter: 

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