| Previous | Table of Contents | Next |
TAGS
Tags provide the ability to edit multiple files via symbolic labels. These symbolic labels or tags are simple strings that you select. There are several steps to making the tag command work.
| Field | Description |
|---|---|
| 1 | The tag (symbolic label) |
| 2 | The file to edit when that tag is specified |
| 3 | The ex commands to interpret when the file is edited |
:set tags=/u1/tech/mylogin/.tags
:set tags=/u1/tech/mylogin/.tags
EXINIT="tags=/u1/tech/mylogin/.tags"
:tag prog1
Tag File Format
The format of the tag file is important; it must contain tag names (symbolic names) sorted in alphabetical order. The second column is the name of the file to be edited. The third column contains the ex edit commands to be processed when the new file is edited. For example, the following is the generic format of the tag file.
label<Tab>file<tab>ex_commands
An example of a tag file follows:
main # /main()/;.-5,.p
which says when you request tag main, the editor will edit the alternate file, search for main(), and display the 5 preceding lines and the current line.
See ctag(1) to build a tag file from C source code files.
Referencing a Tag
To reference a tag in the tag file you enter tag tag, where tag is the tag you wish to reference, and press Return. For example,
:tag label
This causes ex/vi to check the tag file for the tag label in field one. If the label tag is located then ex/vi edits the file specified in field two. Once the file has been read in by ex/vi the ex commands in field three are performed. Then you are placed at the location after the commands have been carried out.
The following example references the main tag defined early. Type
:ta main
and press Return. This tag command would cause ex/vi to edit the alternate file (#), search for the pattern main( ), and print out the 5 lines before main().
NOTE:
The tag file must be in alphabetical order for the tag command to function correctly. If it is not sorted, the tag command will complain about tags not being found.
MACROS
Macros are a special feature of the vi editor that allows you to store multiple keystrokes and reference them with a single or shorter set of keystrokes. You can have multiple vi or ex commands defined in one macro. Macros are discussed in Module 151.
MISCELLANEOUS
The following list is composed of commands that provide various functions.
| range# range nu |
Display the line number and the line. If no range is provided the current line is used. |
| .= | Display the line number of the current line. |
| = | Display the total number of lines in the buffer. |
| ar | Display current file and files to be edited. The current file being edited is enclosed in brackets. |
| cd dir | Change current working directory of editor. The editor performs a UNIX cd command internally. |
| pre | Preserve the file for later recovery using the recover command. |
| rec | Recover the file from a previous preserve. You can preserve the file if you like, but usually preserving is done automatically when your phone line is disconnected, your terminal hangs, or the system crashes. |
| so file | Read and execute commands in file to set/reset editor options. The commands in the file must be ex type commands. Refer to the section that discusses the .exrc file. |
| stop | Stop editor, place it in background, and return to top level shell. Job Control UNIX only, use the fg command to resume editing. |
| ver | Displays the version of ex/vi editor you are using. Believe it or not, different versions have minor differences in their support of features. |
| cmd1 | cmd2 | Sequential editor command separator. Perform editor command cmd1 followed by editor command cmd2. This is not a UNIX pipe command. |
| cmd1 ; cmd2 | Same as above, but only usable in tag files. |
LEAVING ex
There are multiple ways to leave the ex or vi editor. All of the following commands can be used from ex or vi.
| ZZ | Save the current session buffer to disk if any modifications have been made and exit the editor. |
| x file wq file |
Save the current session buffer to disk and quit ex/vi. If file is specified, the buffer is written to that file instead of the current buffer name. |
| q | Quit ex/vi if no modifications have been made since the last save to disk. |
| q! | Quit ex/vi without checking for unsaved modifications. If you have made any changes to the session buffer, they are discarded without warning. This may be useful if you have destroyed vital information. |
| sh | Leave ex/vi; starts a subshell. Press Ctrl-D or type exit to return to ex/vi. |
| Ctrl-Z | Stop the editor, place it in background, and return to top level shell. Job Controlled UNIX only, the fg command resumes editing. |
| Previous | Table of Contents | Next |