From FreeBSDwiki
Jump to: navigation, search

vi is the most minimal of the text editors you're likely to run across. While it is incredibly painful for the novice to use, it is well worth expending the effort to learn the basics anyway - you will probably never encounter a unixlike computer that does not have vi installed, so being able to get by with vi can be crucial when there's some machine that you have to work with now and you don't have time to try to go hunting for whatever editor you normally use.

Since it is a part of the FreeBSD base system, vi will be both installed and in your path, so you can start it by simply typing vi.

Basic Commands in vi

vi has two modes: "command mode" and "editing mode". You can switch between them by hitting the Esc key on your keyboard. Command mode will let you do stuff to the file, like save it or do stuff with the program, like exit out of vi. Edit mode lets you make changes to the file itself. When first run, you're dropped into Edit mode.

Edit Mode


lets you insert text where the cursor is


lets you insert text into the line below where the cursor is


lets you replace the character that the cursor is on


deletes the charater that the cursor is on


deletes the word the cursor is on

Command Mode

If you hit Esc, you'll see your cursor moves to the bottom of the screen: you're in command mode. From here you can type in stuff like


exits the editor without saving the file


writes the file to disk (saves it) and exits the program


searches the file for the text "something"


sends you directly to the 23rd line of the file. Useful when you know what line the error is on and don't want to have to scroll all the way there.

Personal tools