This knowledge base has moved to the documentation site. Please visit the knowledge base here for the most up to date content. This site is no longer maintained.

vi for Beginners


Many new Linux administrators find the vi editor complex and daunting. It is not as user friendly as other editors that they may have used before, but with a little practice, vi can be a powerful tool for managing files.

This article is not intended to make you a master of vi. Instead, it tries to get you comfortable with the editor so that you can learn the more advanced tools as you need them.


vi was originally called the "VIsual editor" because it allowed the entire file to be seen on screen at once. It was first developed in a world without function keys and a mouse. Administrators had just the basic keyboard keys and so had to make the most of what they had to work with. Every key has a function within vi, but how do you separate the text from the commands?


vi has two modes: command and input.

Command mode is the default when you first opens a file. In this mode, your keystrokes perform different actions within the editor. Be careful, however — in order to extend the number of possible commands, vi is case sensitive, so the upper- and lowercase letters almost always have different behaviors. Certain characters — most notably the colon (:) and forward slash (/) — activate an in-application command line for multi-character commands.

Input mode allows text to be entered in the file. You activate this mode with a set of command mode characters. A status bar at the bottom of the screen indicates which input mode is in use. The <esc> key exits input mode and returns the editor to command mode.


Although you can use arrow keys to move through a file in modern incarnations of vi, part of the editor's strength is that you never need to move your hands from the home keys. This means less wasted movement and better efficiency.

The simple movement keys are h, j, k, and l.

Command Action Mnemonic


cursor left

Key is at left of the group on the keyboard


cursor down

"Jump down"


cursor up

"Kick up"


Cursor right

(lowercase letter l) Key is at the right of the group on the keyboard

Many administrators only use these four keys to navigate their files. Once comfortable with the basic movements, the next step is to learn how to move more efficiently.

Command Action


(zero) Go to the front of the current line


Go to the end of the current line


Advance a single word


Go back a single word


Go to the last line of the file

Managing Text

Multiple commands start input mode, depending on where and how the text is placed in the file.

Command Action


Insert text before the current cursor position


Append text after the current cursor position


(uppercase I) Insert text at the front of the current line


Append text at the end of the current line


Replace the letter at the current cursor position


Replace individual characters as the administrator types


(lowercase letter o) Open a line below for adding text


(uppercase letter O) Open a line above for adding text

To manipulate text, the major commands are x (character delete or "strike out"), d (delete), y (copy or "yank"), and p (paste). The y and d commands require additional characters to indicate the amount of text to copy or delete. Prepending a number will repeat an action that number of times.

Command Action


Delete the character after the cursor position


Delete an entire word


Delete an entire line


Yank an entire word


Yank an entire line


Yank to the end of the current line


Paste copied or deleted text after current cursor position


Paste copied or deleted text before current cursor position


Delete the next four words


Undo the last action


Undo all changes since you last entered the current line


Repeat the last action


Closing a File

Like an text editor, vi allows you multiple ways to exit a file, with and without saving. Some of the files require the : character which allows you to see the commands you type on screen.

Command Action


Quit a file (will prompt if a save is needed)


Quit a file forcefully (discards unsaved changes)


Write (save) the file

:w <filename>

Write the file and rename to <filename>


Write forcefully (overrides read-only files that you own)


Write file, then quit


Write file, then quit (also called "putting the file to bed")


This support portal has moved

Cumulus Networks is now part of the NVIDIA Networking Business Unit! The NVIDIA Cumulus Global Support Services (GSS) team has merged its operations with the NVIDIA Mellanox support services team.

You can access NVIDIA Cumulus support content from the Mellanox support portal.

You open and update new cases on the Mellanox support portal. Any previous cases that have been closed have been migrated to the Mellanox support portal.

Cases that are still open on the Cumulus portal will continue to be managed on the Cumulus portal. Once these cases close, they will be moved to the Mellanox support portal.

Powered by Zendesk