vi Editor: UNIX

vi is a command-line text editor originally created for the Unix operating system.

The name vi is derived from the shortest unambiguous abbreviation for the command visual; the command in question switches the line editor ex to visual mode.

Most of the network administrators are familiar with this little editor in Unix, because they use it regularly. But, for first timers, it’s most difficult editor. First timers have to remember all commands and keys to edit a simple file.

vi has two modes, Insert mode and Command mode. In insert mode, you can add/edit the texts in file. And in command mode, you can navigate and command the editor like save, exit, copy, paste, etc.

These are the commands and keys for those who want to get familiar with vi editor.

Command to open the vi editor:

vi filename

This command creates a new file if filename is not available in current directory. By default, vi begins in command mode.

To start the insert mode, you can use following keys:

Insert text at beginning of line:


Insert text at cursor:


append text after cursor:


Append text at line end:


Open line above cursor:


Open line below cursor:


To switching back, and start the Command mode, press [ESC]

Most commands execute as soon as typed except for “colon” commands which execute when you press the return key.

For cursor movement in command mode, you can use following commands/keys:

Go to beginning of line


Go to end of line


Go to line number ##


Go to line n


Go to last line


Left 6 chars


Move left, down, up, right

h j k l

Move left, down, up, right

← ↓ ↑ →

Scroll Backward 1 screen

[ctrl] b

Scroll Forward 1 screen

[ctrl] f

Scroll by sentence forward/backward

( )

Scroll by word forward/backward

w b

Scroll by paragraph forward/backward

{ }

Scroll Up 1/2 screen

[ctrl] u

Scroll Down 1/2 screen

[ctrl] d

For deleting/changing text/character in command mode, you can use following commands/keys:

Change word


Replace one character


Delete word


Delete text at cursor


Delete entire line (to buffer)


Delete (backspace) text at cursor


Delete 5 lines (to buffer)


Delete current to end of line


Delete lines 5-10


For editing content in command mode, you can use following commands/keys:

Copy line


Copy n lines


Copy lines1-2 /paste after 3


Move lines 4-5/paste after 6


Paste above current line


Paste below current line


Undo all changes to line


Undo previous command


Join previous line


Find next string occurrence


Search backward for string


Search forward forstring


% (entire file) s (search and replace) /old text with new/ c (confirm) g (global – all)


Ignore case during search

:set ic

Repeat last command


For saving and quiting in command mode, you can use following commands/keys:

Save changes to buffer


Save changes and quit vi

zz or :wq

Save file to new file

:w file

Quit without saving


Save lines to new file

:10,15w file

In all of the above commands, a number n will tell vi to repeat that command n times.

:syntax on Turn on syntax highlighting
:syntax off Turn off syntax highlighting
:set number Turn on Line numbering (shorthand :set nu)
:set nonumber Turn off Line numbering (shorthand :set nonu)

:set ignorecase Ignore case sensitivity when searching
:set noignorecase Restore case sensitivity (default)



4 thoughts on “vi Editor: UNIX”

  1. Great ˇV I should certainly pronounce, impressed with your web site. I had no trouble navigating through all tabs as well as related info ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Reasonably unusual. Is likely to appreciate it for those who add forums or something, site theme . a tones way for your customer to communicate. Nice task..

  2. I see a lot of interesting posts on your blog.
    You have to spend a lot of time writing, i know how to
    save you a lot of time, there is a tool that creates unique,
    SEO friendly articles in couple of minutes, just search in google – k2 unlimited

  3. Hello there! This post couldn’t be written any better! Reading through this post reminds me of my good old room mate! He always kept chatting about this. I will forward this post to him. Fairly certain he will have a good read. Many thanks for sharing!

Comments are closed.