NMSU::Information & Communication Technologies
NMSU home page ICT Home Page
Send a message to:
Computer Help Accessibility Services Departments Guidelines/Policies About Us Computer Labs
 


Using the VI editor

Overview

VI is a UNIX editor that allows you to create and modify programs or bodies of text.

Creating Or Editing A File With VI

To create or edit a file with vi, type:
vi [filename]
If the file does not already exist, it will be created.

Changing Between Command And Insert Modes

There are two modes in vi: command mode and insert mode. When vi starts up in command mode. As such, any key pressed will be interpretted by vi as a command, rather than text.

Before you can enter text, you must change to insert mode. Do this by typing:

	a
for append or:
	i
for insert.

Insert mode works just like a typewriter. Anything you type will be inserted into your document. When you are done typing and ready to get back into command mode, press .

Moving The Cursor In VI

These commands allow for navigation while in command mode:
	COMMAND:		ACTION:
	h			move left one character 
	j			move down one line
	k			move up one line
	l			move right one line

Inserting Text

These commands change to insert mode: (Hit to return to command mode)
	a			append text after the cursor
	i			insert text under the cursor
	o			insert a new line beneath the cursor
	O			insert a new line above the cursor 

Deleting Text

These commands delete text while staying in command mode:
	x			delete the character under the cursor
	dw			delete from cursor to end of word
	dd			delete the line the cursor is on

Saving And Quitting

These commands save and/or quit from vi: (Must be in command mode)
	:w		write (save) the file
	:wq		write (save) the file and quit vi
	:q		quit out of vi
	:q!		quit without saving changes

For More Information

Contact the Information Center at 646-1840

Search the NMSU site Phone numbers and e-mails of faculty, staff, and students Go to NMSU Home

Questions? Comments? Send us e-mail.

Last Modified: Sunday, January 13, 2008

Copyright 2006, Regents of New Mexico State University