DEV Community

Cover image for vi (visual editor)
Haile Melaku
Haile Melaku

Posted on • Updated on

vi (visual editor)

Now that you are here you need to choose which text editor to code with and this is a serious decision you have to make.
The most common and widely used text editors are Emacs and vi, so we are going to cover vi in this post and i will explain Emacs in the next blog post.

vi (visual editor) is a default editor that comes with the UNIX operating system.

Okay now lets talk about vi, well vi gets a bad rep some times because it hard to learn for beginners but once you get to know it, its fairly simple to use and effective.
one advantage i like about vi is that you can find it on any Linux OS except on Ubuntu then you might have to reinstall it properly.


lets get into it then,so vi is a full screen editor(doesn't allow you to type any command in the terminal while it is open and it covers the hole terminal) and it has two base of operation.

  • Command mode: for manipulate the file

Image description

  • Insert mode : for typing text

Image description

To Get Into and Out Of vi

Create a file in vi

vi hello.txt

Image description
Exit vi

If you are in Insert mode you need click Esc or Ctrl [, then enter the commands.

On command mode

:x to save the file and quit
:w Save and continue editing.

Image description

:q! to quit without saving the file

Image description

Moving the Cursor

In vi you must use the keyboard to navigate around and this saves you time because you don't constantly use the mouse then get back to the keyboard.

some navigation keys are

On command mode

j move cursor down one line
k move cursor up one line
h move cursor left one character
l move cursor right one character

Image description
0 move cursor to start of current line (the one with the cursor)
$ move cursor to end of current line

Adding, Changing, and Deleting Text

Undo

On command mode

:u UNDO WHATEVER YOU JUST DID

Image description
i insert text before cursor
x delete single character under cursor
dd delete entire current line
yy copy (yank, cut) the current line into the buffer
p put (paste) the line(s) in the current line

This are the important commands to know vi

Tip: Read the documentation to vi in here vi

Top comments (0)