Ready to Start Your Career?

Get Familiar with Visual Editor

KMCLink s profile image
By: KMCLink
April 23, 2018

Get Familiar with VI

There are so many text editors for *nix systems, but VI is surely the most historically widespread. VI stands for "Visual editor", and VIM is an "IMproved" version of VI that can usually be installed via a package manager. You can find Visual Editor (VI) in any Linux distribution, in many Unix flavors, as well as Mac Os X systems. VI is a textual editor, so you do not have all the bells and whistles that are so common with graphical text editors.  This intimidates some people, but when you do not have a desktop, a textual editor may be all that is available.  The fact that it is available in all *nix platforms guarantees it will be available regardless of the system you are logged into.  Learning how to use visual editor will prevent you from wasting time looking for an editor while working on a  *nix system.There are three modes in VI:1) normal mode2) insert mode3) commandTo run VI, open a Terminal window and type 'vi [SomeFile]'. As soon as you entered VI, you were dropped into normal mode. To enter insert mode, just press the 'i' or 'a' key.Let's see a simple editing session:

vi myfile (you are creating a file called 'myfile')-press 'i' (to enter input mode), and then type 'this is a simple text file.' to insert your text into the file.-hit the 'Esc' key (this takes you back to normal mode.).-now press ':' (to enter command mode) and then 'wq!' (this is the command that will write the file and close VI).#

Now, wasn’t that easy?  Below find some common commands to help get you started with VI…Normal mode commandsw -> go to the beginning of the next wordb -> go to the beginning of the previous worde -> go to the end of the next wordn| -> go to the 'n' columns of the current row$ -> go to the end of the current row^ -> go to the first character of the current rowG -> go to the end of the filegg -> go to the beginning of the fileGn -> go to 'n' row of the filex -> delete one characternx -> delete 'n' charactersdd -> delete the whole rowndd -> delete 'n' rowsyy -> copy the current rowp -> paste the copied rowRmystring -> replace next characters with the string 'mystring'/string -> find the next string 'string'?string -> find the string 'string' backwardsn -> repeat the search againu -> undo the last commandInsert mode commandsi -> insert mode (before the cursor)a -> insert mode (after the cursor)o -> insert mode (under the current row)Command mode commands:w -> write the file:w myfile -> write the file as 'myfile':q -> quit the file:wq -> write and quit the file:q! -> quit without saving the file:help -> open the help file (:q to return editing the file):help topic -> open the help file showing the subject 'topic' (:q to return editing the file):rs/string1/string2/[options] -> replace string1 with string2 withing the 'r' range; options may be: g (replace all), c (ask before any replacement):set number -> set rows numbering
You can learn more commands (there are so many commands) with the :help command. Of course, you can also use the 'man vi' command from a shell prompt as well. The best way to learn VI is to just start using it.
Schedule Demo
Build your Cybersecurity or IT Career
Accelerate in your role, earn new certifications, and develop cutting-edge skills using the fastest growing catalog in the industry