Get Familiar with Visual Editor

April 23, 2018 | Views: 478

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

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 mode
2) insert mode
3) command

To 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 commands

w -> go to the beginning of the next word

b -> go to the beginning of the previous word

e -> go to the end of the next word

n| -> 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 row

G -> go to the end of the file

gg -> go to the beginning of the file

Gn -> go to ‘n’ row of the file

x -> delete one character

nx -> delete ‘n’ characters

dd -> delete the whole row

ndd -> delete ‘n’ rows

yy -> copy the current row

p -> paste the copied row

Rmystring -> replace next characters with the string ‘mystring’

/string -> find the next string ‘string’

?string -> find the string ‘string’ backwards

n -> repeat the search again

u -> undo the last command

Insert mode commands

i -> 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.

Share with Friends
Use Cybytes and
Tip the Author!
Share with Friends
Ready to share your knowledge and expertise?
Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Cybrary On The Go

Get the Cybrary app for Android for online and offline viewing of our lessons.

Get it on Google Play

Support Cybrary

Donate Here to Get This Month's Donor Badge

Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?