Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
UNIX VI Editor

UNIX VI Editor



|Views: 692 |Likes:
Published by leopard_friend
Commands to use VI Editor in UNIX
Commands to use VI Editor in UNIX

More info:

Published by: leopard_friend on May 02, 2008
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





University of Hawaii at ManoaCollege of EngineeringMastering the VI editor
Before You Begin
Starting the VI Editor
Getting Out of VI
The Two Modes of VI
How to Type Commands in Command Mode
Some Simple VI Commands
Text Buffers in VI
Cutting and Yanking
Indenting Your Code and Checking
Word and Character Searching
Settings for VI (and EX)
Abbreviations and Mapping Keys to Other Keys
The EXINIT Environment Variable and the
Recovering Your Work When Something Goes Wrong with Your Terminal
Warning About Using VI on the Workstations
Summary of VI Commands
Cutting and Pasting/Deleting text
Inserting New Text
Moving the Cursor Around the Screen
Replacing Text
Searching for Text or Characters
Manipulating Character/Line Formatting
Saving and Quitting
EX Commands
The VI editor is a screen-based editor used by many Unix users. The VI editor haspowerful features to aid programmers, but many beginning users avoid using VIbecause the different features overwhelm them. This tutorial is written to helpbeginning users get accustomed to using the VI editor, but also contains sectionsrelevant to regular users of VI as well. Examples are provided, and the best way tolearn is to try these examples, and think of your own examples as well... There's nobetter way than to experience things yourself.
In this tutorial, the following convention will be used:
denotes a control character. For example, if you see:
in the tutorial, thatmeans you hold down the control key and then type the corresponding letter. For thisexample, you would hold down the
key and then type
Before You Begin
The VI editor uses the full screen, so it needs to know what kind of terminal you have.When you log in, wiliki should ask you what terminal you have. The prompt looks likethis:
TERM = (vt100)
If you know your terminal is a vt100 (or an emulator that can do vt100), just hitreturn for the terminal type when you log in. If you have an hp terminal, type "
" forthe terminal type and hit return. If you are not sure what kind of terminal you have,ask a lab monitor, or have someone help you set the correct terminal type.If you make an error when you log in and type the wrong terminal type, don't panicand log out. You can type the following commands to fix the settings:First, tell your shell what type of terminal you have. (If you're not sure whatyour shell is, type this command to see what shell you have:
echo $SHELL
.) Forthe examples given, the terminal type is "vt100". Substitute it with whateverterminal type you have. For C shell (/bin/csh), the command is this:
set term=vt100
For Bourne Shell (/bin/sh) or Korn Shell (/bin/ksh), the commands are the following:
export TERMTERM=vt100
Next, reset your terminal with this command:
Now that the terminal type is (hopefully) correctly set, you are ready to get startedwith VI.
Starting the VI Editor
The VI editor lets a user create new files or edit existing files. The command to startthe VI editor is
, followed by the filename. For example, to edit a file called
, you would type
vi temporary
and then return. You can start VI without afilename, but when you want to save your work, you will have to tell VI whichfilename to save it into later.When you start VI for the first time, you will see a screen filled with tildes (A tildelooks like this: ~) on the left side of the screen. Any blank lines beyond the end of thefile are shown this way. At the bottom of your screen, the filename should be shown,if you specified an existing file, and the size of the file will be shown as well, likethis:
"filename" 21 lines, 385 characters
If the file you specified does not exist, then it will tell you that it is a new file, like this:
"newfile" [New file]
If you started VI without a filename, the bottom line of the screen will just be blank when VIstarts. If the screen does not show you these expected results, your terminal type may be setwrong. Just type
and return to get out of VI, andfix your terminal type.If you don't know how, ask a lab monitor.
Getting Out of VI
Now that you know how to get into VI, it would be a good idea to know how to get outof it. The VI editor hastwo modes and in order to get out of VI, you have to be in
mode. Hit the key labeled "
" or "
" (If your terminal does not havesuch a key, then try ^[, or control-[.) to get into
mode. If you were alreadyin the command mode when you hit "
", don't worry. It might beep, but you willstill be in the
mode.The command to quit out of VI is
. Once in
mode, type colon, and 'q',followed by return. If your file has been modified in any way, the editor will warn youof this, and not let you quit. To ignore this message, the command to quit out of VIwithout saving is
. This lets you exit VI without saving any of the changes.Of course, normally in an editor, you would want to save the changes you have made.The command to save the contents of the editor is
. You can combine the abovecommand with the quit command, or
. You can specify a different file name tosave to by specifying the name after the
. For example, if you wanted to save thefile you were working as another filename called
, you would type:
and return.

Activity (3)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
bibhu53 liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->