⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vi.hlp

📁 vi帮助文档!希望对需要的人有帮助!带来操作便捷!
💻 HLP
📖 第 1 页 / 共 4 页
字号:
subcommand from the command line.To set vi options for all editing sessions, put the :set subcommand in theEXINIT environment variable in the .profile file (read by the shell on login) orput the set subcommand into a .exrc file. The vi editor first looks for theEXINIT environment variable and runs its commands. If the EXINIT environmentvariable does not exist, the vi editor then looks for the $HOME/.exrc file andruns its commands. Last, and regardless of any previous results, the vi editorlooks for the local .exrc file and runs its commands. Note This process is trueexcept with the tvi command (trusted vi). In this instance, the vi editor looksfor and runs only the /etc/.exrc file.For information about changing an option by setting the EXINIT environmentvariable, see the description of environment variables in the environment file.The .exrc file can contain subcommands of the form set Option=Value; forexample:set cp=3 . . ;To include a comment in the .exrc file, use a " (double quotation mark) as thefirst character in the line.Defining MacrosIf you use a subcommand or sequence of subcommands frequently, you can use thevi editor to define a macro that issues that subcommand or sequence.To define a macro, enter the sequence of subcommands into a buffer named with aletter of the alphabet. The lowercase letters a through z overlay the contentsof the buffer, and the uppercase letters A through Z append text to the previouscontents of the buffer, allowing you to build a macro piece by piece.For example, to define a buffer macro named c that searches for the word cornerand makes the third line after the word corner the current line, enter thefollowing command:o /corner/+3Then press the Esc key and enter the following command:"cwhere c is the name of the buffer macro.To add text to the previous contents of the defined buffer, enter the oviSubcommand, press the Esc key, and enter "CapitalLetter, where theCapitalLetter variable specifies an uppercase letter A through Z. For example,to build a buffer macro named T that searches for the word corner and allows youto add more commands, enter the following command:o cornerThen press the Esc key and enter the following command:"Twhere T is the name of the buffer macro. You can repeat this process at any timeto add more vi subcommands to the same buffer.For example, to add commands that move the cursor to the previous line anddelete that line, enter the following command:o -ddwhere - (minus sign) means to move the cursor up one line, and dd means todelete the current line. Press the Esc key and enter the following command:"TddTo start the macro, enter @Letter, where the Letter variable specifies theletter name of the buffer macro you want to use. To use the same macro again,enter @@ (two at symbols). For example, enter @T to start the T buffer macro andrun the search, move cursor, and delete line commands. Enter @@T to start the Tbuffer macro again.The character set used by your system is defined by the collation table. Thistable affects the performance of vi macros.Mapping KeysYou can use the :map, :map!, and :ab subcommands to map a keystroke to a commandor a sequence of commands. The :map subcommand is used in the command mode. The:map! and :ab subcommands are used in the text input mode. You can map keys forthis editing session and all future editing sessions or only for the currentediting session from either mode.To map keys for all future editing sessions, put the subcommand into a$HOME/.exrc file. Each time you start the vi editor, it reads this file. Themapping remains in effect for every editing session.To map keys for the current editing session only from the command mode, startthe subcommand during the vi editor session. To map keys for the current editingsession only from the text input mode, enter the subcommand on the command lineduring the vi editor session. The mapping remains in effect only for the currentediting session.Attention: If you use an IBM 3161 ASCII display station, IBM 3163 ASCII displaystation, or IBM 3101 ASCII display station, the default key-mapping of the vieditor can cause you to lose data. To see the default mapping, issue a :mapsubcommand. Specific problems arise with the Esc-J or Shift-J key sequence.These key sequences delete all information from the current position of thecursor to the end of the file. To avoid problems, change this key sequence usinga .exrc file.The :map, :map!, and :ab subcommands are defined and used as follows::map Defines macros in the command mode. The :map subcommand allows you to run aspecified command or sequence of commands by pressing a single key while in thevi editor.To map keys in the command mode, start the vi editor with an empty editingbuffer and do not name a vi file using the vi command or type anything into thebuffer after the vi editor starts. You can use the :map subcommand to do thefollowing:  o To map a character to a sequence of editing commands, enter:    :map Letter viSubcommand  o To unmap a character previously mapped in command mode, enter:    :unmap Letter  o To display a list of current mappings for the command mode, enter    :mapThe following keys are not used by the vi editor, but are available for use withthe :map subcommand in the command mode:  o Letters g, K, q, V, and v  o Control key sequences Ctrl-A, Ctrl-K, Ctrl-O, Ctrl-T, Ctrl-W, and Ctrl-X  o Symbols _ (underscore), * (asterisk), \ (backslash), and = (equal sign)Although you can map a key that is already used by the vi editor, the key'susual function is not available as long as the map is in effect. Some terminalsallow you to map command sequences to function keys. If you are in LISP mode,the = (equal sign) cannot be used because it is used by the vi editor.To map the letter v to the sequence of commands that would locate the nextoccurrence of the word map and change it to the word MAP, enter the followingcommand::map v /map<Ctrl-V><Enter>cwMAP<Ctrl-V><Esc><Ctrl-V><Enter>The previous example instructs the vi editor to locate the next occurrence ofmap (/map<Ctrl-V><Enter>), change map to MAP (cwMAP), end the change-wordsubcommand (<Ctrl-V><Esc>), and enter the command (<Ctrl-V><Enter>).Note To prevent the vi editor from interpreting the Enter key, it must bepreceded by the Ctrl-V key sequence when being mapped. This condition is alsotrue of the Esc, Backspace, and Delete keys.To map the control characters Ctrl-A, Ctrl-K, and Ctrl-O, simultaneously pressthe Ctrl key and the letter. For example, to map the Ctrl-A key sequence to thesequence of commands that saves a file and edits the next one in a series, enterthe following command::map <Ctrl-A> :w<Ctrl-V><Enter>:n<Ctrl-V><Enter>To map the control characters Ctrl-T, Ctrl-W, and Ctrl-X, you must first escapethem with the Ctrl-V key sequence.To map the | (pipe symbol), you must first escape it with the two Ctrl-V keysequences, as illustrated by the following example that maps the character g tothe sequence of commands that escapes to the shell, concatenates the file/etc/motd, and pipes the output to the wc command::map g :!cat /etc/motd <Ctrl-V><Ctrl-V>| wc<Ctrl-V><Enter>If your terminal permits you to map function keys, you must reference them withthe #number key sequence to designate the number of the function key that youwant to map. In the following example, the F1 function key is mapped to thesequence of commands that deletes a word and moves the cursor three words down::map #1 dwwwwIn order for function key mapping to work, the output of the function key foryour terminal type must match the output defined in the terminfo file. Thesedefinitions are denoted by the kfnumber entries, where kf1 represents the F1function key, kf2 represents the F2 function key, and so on. If the output thatyou get when you press the function key does not match this entry, you must usethe terminal's setup mode to correct the settings to match these terminaldatabase entries before any mapping can occur.You can also map certain keyboard special keys, such as the Home, End, Page Up,and Page Down keys. For most terminals, these keys are already mapped in the vieditor. You can verify this mapping by using the :map subcommand. If these keysare not already mapped, you can use the :map subcommand as follows::map <Ctrl-V><End> G:map <Ctrl-V><Home> 1G:map <Ctrl-V><PageUp> <Ctrl-F>:map <Ctrl-V><PageDown> <Ctrl-B>To get a listing of all current maps in the command mode, enter the :mapsubcommand. The preceding examples are then displayed as follows:v         v          /map<Ctrl-M>cwMAP<Ctrl-[>Ctrl-M><Ctrl-A>  <Ctrl-A>   :w<Ctrl-M>:n<Ctrl-M>g         g          :!cat /etc/motd | wc <Ctrl-M>Note The Ctrl-V and Enter key sequence is displayed as the Ctrl-M key sequence,and the Ctrl-V and Esc key sequence is displayed as the Ctrl-[ key sequence.:map! Maps character strings to single keys while in text input mode. To mapkeys in the text input mode, start the vi editor with an empty editing bufferand do not name a vi file using the vi command or type anything into the bufferafter the vi editor starts. You can use the :map! subcommand to do thefollowing:  o To map a letter to one or more vi strings in text input mode, enter:    :map! Letter String  o To unmap a letter previously mapped in text input mode, enter:    :unmap! Letter  o To display a list of existing strings that are mapped to specific keys in    text input mode, enter:    :map!Typing the mapped key while in text input mode produces the specified string.The Ctrl-V and Esc key sequence puts you into command mode, backs up to thebeginning of the current word (bbw), and starts the cw (change-word) subcommand.For example::map! % <Ctrl-V><Esc>bbwcwWhen typing text, if you realize that you have mistyped a word, you can changeit by pressing the % (percent) key and retyping the word. You are automaticallyreturned to insert mode.Note Be careful when choosing keys to be used for the :map! subcommand. Oncekeys have been mapped, they can no longer be input as text without first issuingthe :unmap! subcommand.:ab Maps a key or sequence of keys to a string of characters for use in the textinput mode. The :ab subcommand is useful when inputting text that possessesseveral repetitive phrases, names, or titles.The following example replaces the word city with the phrase Austin, Texas 78759whenever it is typed in text input mode and followed by a white space, period,or comma::ab city Austin, Texas 78759For example, if while inputting text, you type the following:My current residence is city.Pressing the Tab key expands the word city to read:My current residence is Austin, Texas 78759.The abbreviation is not expanded within a word. For example, if you type Mycurrent residence iscity, the word iscity is not expanded.If the :map! subcommand is used to map abbreviations for insert mode, then alloccurrences of the abbreviations are expanded regardless of where it occurs. Ifyou used the :map! subcommand for the preceding example (:map! city Austin,Texas 78759), then whenever you type the word city, regardless of what precedesor follows, the word will be expanded to Austin, Texas 78759. Therefore, theword iscity becomes isAustin, Texas 78759.Note Be careful when choosing the keys that are used for the :ab subcommand.Once keys are defined, they can no longer be input as text without first issuingthe :unab subcommand.Setting AbbreviationsThe set command has behavior similar to the map! command except that the setcommand substitutes the string for the abbreviation only when the abbreviationis a separate word. You can use the set command of the vi editor to:  o List existing abbreviations  o Remove an abbreviation  o Set (define) an abbreviation Note Start the vi editor with an empty editing    buffer. Do not name a vi file using the vi command or type anything into the    buffer after the vi editor starts. Press the Esc key to be sure you are in    the command mode.    To list abbreviations Enter the :ab command to list existing abbreviations.    Press the Enter key to return to command mode.    To remove abbreviations Enter the :anabAbbreviation command to remove an    abbreviation, where the Abbreviation variable specifies the character string    you do not want abbreviated any more.    To set (define) an abbreviation Enter the :ab Abbreviation String command to    set an abbreviation, where the Abbreviation variable specifies the character    string being defined as an abbreviation and the String variable specifies    the character string being abbreviated. The abbreviation can be substituted    for the string only when the abbreviation is a separate word.    For example, if you enter the :ab kn upper command and then type acknowledge    while in the text input mode, the set abbreviation string is not started    because the kn string in the word acknowledge is not a separate word.    However, if you type the :ab kn upper command and then type make the kn line    all kncase while in the text input mode, the result is make the upper line    all uppercase.Flags-cSubcommand Carries out the ex editor subcommand before viewing with vi begins.The cursor moves to the line affected by the last subcommand to be carried out.When a null operand is entered, as in -c' ', the vi editor places the cursor onthe first line of the file. The -c flag is incompatible with the + flag. Do notspecify both flags at the same time.-l Enters the vi editor in LISP mode. In this mode, the vi editor creates

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -