All DECS accounts are set to utilize VI.
To begin editing a file, at the system prompt type:
Note that the editor does not directly modify the file which you are editing; the editor makes a copy of this file in the buffer and remembers the file's name. You do not affect the contents of the file until you write the changes you have made into the original file.
There are two modes in VI: MOVING and INSERTING. In MOVING mode, you can move about your document with the arrow keys, delete characters or lines of text as well as perform cut and paste, search or search and replace functions. In INSERTING MODE you can add text to your current document.
By pressing the forward-slash ( / ) key, VI will put you at the bottom of the window with the slash displayed. You can now type in the word or words you wish to search for and press RETURN. VI will go through the document (starting from the current cursor position, going down, then to the top and back down repeatedly) and find occurrences of the string you entered. It will stop at each occurrence and you will need to press n (for next) to get to the next occurrence.
Press the colon ( : ) key and VI will put you at the bottom of the window at the colon prompt. Type in a range of line numbers you wish to search in (i.e. 1,100 will search from lines 1 through 100); type a forward slash and 's' ( /s ) to enter the string to search for; type another forward slash ( / ), and finally enter the replacement string.
Example: :1,100s/dog/cat will search from line 1 through 100 and replace all occurrences of the string dog with the string cat.
VI will only find the first occurrence PER LINE of the search string (i.e. dog), unless you specify that you want it to match every occurrence on each line. This can be done by adding /g onto the end of your search command.
All of the VI functions above can be performed multiple times by first typing a number before the function. Some common examples are:
22dd - Delete 22 lines under the cursor
22yy - "Yank" 22 lines into the buffer
22k - Move Up 22 lines from current cursor position
22x - Delete 22 characters from current cursor position --> right
You can press the u key after most functions to undo the last move.
To insert text you must be in INSERT MODE. To enter this mode, press one of the following one-key commands:
Once you have completed your text, you can get back into MOVING MODE by pressing the ESCAPE key.
In order to enter save/quit commands in VI you must be at the colon prompt. This prompt may be obtained by being in MOVING MODE and pressing the colon key. A colon will be displayed at the bottom of your window along with your cursor. Enter the following commands at this prompt to quit and/or save:
q - quit (exits VI only if you haven't changed/edited your file)
q! - unconditional quit (exits VI even if you changed your file)
wq - write and quit (saves your file and exits VI)
w - write your file to a new filename
w! - unconditional Write (saves your current file and stays in VI)
Below are VI variables that control the operation of your VI session. They can be set from within your session (using : set) and also initialized by the EXINIT environment variable or the .exrc file.
Since the system login file /opt/lib/sys.login contains sets EXINIT and use of system files is preferred, it is recommended to custom your VI variables in your .cshrc file using a line similar to the following:
setenv EXINIT 'set ai redraw sm exrc wm=5'
While using VI, type:
to get the following list:
---------------------- vi variables ---------------------
autoindent nomodelines noshowmode autoprint nonumber noslowopen noautowrite nonovice tabstop=8 nobeautify nooptimize taglength=0 directory=/var/tmp paragraphs=IPLPPPQPP LIpplpipnpbtags=tags /usr/lib/tags noedcompatible prompt tagstack noerrorbells noreadonly term=xterm noexrc redraw noterse flash remap timeout hardtabs=8 report=5 ttytype=xterm noignorecase scroll=12 warn nolisp sections=NHSHH HUuhsh+c window=24 nolist shell=/bin/csh wrapscan magic shiftwidth=8 wrapmargin=0 mesg showmatch nowriteany