📄 vi.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>vi</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_2809"> </a>NAME</h4><blockquote>vi - screen-oriented (visual) display editor</blockquote><h4><a name = "tag_001_014_2810"> </a>SYNOPSIS</h4><blockquote><pre><code>vi <b>[</b>-rR<b>][</b>-l<b>][</b>-c <i>command</i><b>][</b>-t <i>tagstring</i><b>][</b>-w <i>size</i><b>][</b><i>file</i>...<b>]</b>vi <b>[</b>-rR<b>][</b>-l<b>][</b>+<i>command</i><b>][</b>-t <i>tagstring</i><b>][</b>-w <i>size</i><b>][</b><i>file</i>...<b>]</b></code></pre></blockquote><h4><a name = "tag_001_014_2811"> </a>DESCRIPTION</h4><blockquote>The<i>vi</i>(visual) utility is a screen-oriented text editor.The user can switch back and forth between<i>vi</i>and the line editor<i><a href="ex.html">ex</a></i>and execute<i><a href="ex.html">ex</a></i>commandsfrom within<i>vi</i>.<p>When using<i>vi</i>,the terminal screen acts as a window into theediting buffer.Changes made to the editing buffer are reflected in the screen display;the position of the cursor on the screen indicatesthe position within the editing buffer.<p>Certain block-mode terminals do not have all the capabilitiesnecessary to support the complete<i>vi</i>definition.When these commands cannot be supported on such terminals, thiscondition will not produce an error message such as "not an editorcommand" or report a syntax error.The implementation may either accept thecommands and produceresults on thescreen that are the result of an unsuccessful attempt to meet therequirements of this specification orreport an errordescribing the terminal-related deficiency.</blockquote><h4><a name = "tag_001_014_2812"> </a>OPTIONS</h4><blockquote>The<i>vi</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b> </a> except for the obsolescent<i>+command</i>option.<p>The following options are supported:<dl compact><dt><b>-c </b><i>command</i><dd><dt>+<i>command</i><dd>Begin editing by executing the specified<i><a href="ex.html">ex</a></i>command-mode commands.As with normal<i><a href="ex.html">ex</a></i>command-line entries, the<i>command</i>option-argument can consist of multiple<i><a href="ex.html">ex</a></i>commands separatedby vertical-line characters(|).The use of commands that enter input modein this manner produces undefined results.<dt><b>-l</b><dd>Set lisp mode (see<xref href=exedops><a href="ex.html#tag_001_014_598_052">Edit Options in ex</a></xref>).<dt><b>-r</b><dd>Attempt to recover the named<i>file</i>safter an editor or system crash, afterthe editor has been terminated by a signal or after the use of a<b>pre</b>(<i>ex</i>)editor command.If no<i>file</i>operands are given,all other options, the<i>EXINIT</i>variable, and any<b>.exrc</b>files will be ignored;a list of all recoverable filesavailable to the invoking user will be written;and<i>vi</i>will exit without reading files or processing user commands.<dt><b>-R</b><dd>Set read-only mode, preventing accidental overwriting of the files.Any command that would write to a file requires the"!"suffix (see, for example, the<b>write</b>command)to be effective in this mode.<dt><b>-t </b><i>tagstring</i><dd>Edit the file containing the specified<i>tagstring</i>and set the initial position within the edit bufferto the point of definition of the tag.(See<i><a href="ctags.html">ctags</a></i>.)The tags feature represented by<b>-t</b> <i>tagstring</i>and the<b>ta</b>command is optional.It is provided on any system thatalso providesa conformingimplementation of<i><a href="ctags.html">ctags</a></i>;otherwise, the use of<b>-t</b>produces undefined results.<dt><b>-w </b><i>size</i><dd>Set the value of the<i>window</i>editor option to<i>size</i>.See the<b>window</b>option.</dl><p>If both the<b>-t</b> <i>tagstring</i>and<b>-c</b> <i>command</i>(or the obsolescent<i>+command</i>)options are given, the<b>-t</b> <i>tagstring</i>will be processed first; that is,the file containing the tag is selected by<b>-t</b>and then the command is executed.</blockquote><h4><a name = "tag_001_014_2813"> </a>OPERANDS</h4><blockquote>The following operand is supported:<dl compact><dt><i>file</i><dd>A pathname of a file to be edited.</dl></blockquote><h4><a name = "tag_001_014_2814"> </a>STDIN</h4><blockquote>The standard input consists of a series of commandsand input text, as described in the EXTENDED DESCRIPTION section.</blockquote><h4><a name = "tag_001_014_2815"> </a>INPUT FILES</h4><blockquote>Input files must be text files or files that would be text filesexcept for an incomplete last line that is not longer than{LINE_MAX}- 1 bytes in length and contains no NUL characters.The editing of other forms of files may optionally be allowed by<i>vi</i>implementations.<p>The<b>.exrc</b>files (see the EXTENDED DESCRIPTION section)must be text files consisting of<i><a href="ex.html">ex</a></i>commands.<p>By default,<i>vi</i>will read lines from the files to be edited withoutinterpreting any of those lines as any form of editor command.</blockquote><h4><a name = "tag_001_014_2816"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>vi</i>:<dl compact><dt><i>COLUMNS</i><dd>Override the system-selected horizontal screen size.Seethe <b>XBD</b> specification, <a href="../xbd/envvar.html"><b>Environment Variables</b> </a> for valid values and results when it is unset or null.<dt><i>EXINIT</i><dd>Determine a list of<i><a href="ex.html">ex</a></i>commands that will be executed on editor startup,before reading the first file.The list can contain multiple commands by separatingthem using a vertical-line(|)character.See also the EXTENDED DESCRIPTION sectionfor more details of the initialisation phase.<dt><i>HOME</i><dd>Determinea pathname of a directory that will be searched for an editorstartup file named<b>.exrc</b>;see the EXTENDED DESCRIPTION section.<dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_COLLATE</i><dd>Determine the locale for thebehaviour of ranges, equivalence classesand multi-character collating elementswithin regular expressions.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments and input files),the behaviour of character classes within regular expressions,the classification of characters as upper- or lower-case letters,the case conversion of letters,and the detection of word boundaries.<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard errorand informative messages written to standard output.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i><dt><i>LINES</i><dd>Override the system-selected vertical screen size,used as the number of lines in a screenful and the verticalscreen size in visual mode.Seethe <b>XBD</b> specification, <a href="../xbd/envvar.html"><b>Environment Variables</b> </a> for valid values and results when it is unset or null.<dt><i>PATH</i><dd>Determine the search pathfor the shell command specified in the editor commands<b>shell</b>,<b>read</b>and<b>write</b>and the visual-mode command"!";see the description of command search and execution in<xref href=cmdsea><a href="chap2.html#tag_001_009_001_001">Command Search and Execution</a></xref>.<dt><i>SHELL</i><dd>Determinethe preferred command-line interpreter for use in"!",<b>shell</b>,<b>read</b>and other commands with an operand of the form!<i>string</i>For the<b>shell</b>command the program will be invoked with the single argument<b>-i</b>,for all others it will be invoked with the two arguments<b>-c</b>and<i>string</i>.If thisvariable is null or not set, the<i><a href="sh.html">sh</a></i>utility will be used.<dt><i>TERM</i><dd>Determine the name of the terminal type.If this variable isunset or null, an unspecified default terminal type will be used.</dl></blockquote><h4><a name = "tag_001_014_2817"> </a>ASYNCHRONOUS EVENTS</h4><blockquote>The following actions will be taken upon receipt of signals:<dl compact><dt>SIGINT<dd>The current editor command will be aborted.The editor will prompt for another command.<dt>SIGCONT<dd>The screen will be refreshed (if in<i>visual</i>mode).<dt>SIGHUP<dd>If the current buffer has changed since the lasteorwcommand,<i>vi</i>will attempt to save the current file in a state suchthat it can be recovered later by an<i><a href="ex.html">ex</a></i>or<i>vi</i><b>-r</b>command.</dl><p>The action taken for all other signals is unspecified.</blockquote><h4><a name = "tag_001_014_2818"> </a>STDOUT</h4><blockquote>If standard output is a terminal device,it may be used for writing prompts to the user,for informational messages and for writing lines from the file.If standard output is not a terminal device,undefined results occur.</blockquote><h4><a name = "tag_001_014_2819"> </a>STDERR</h4><blockquote>Used only for diagnostic messages.</blockquote><h4><a name = "tag_001_014_2820"> </a>OUTPUT FILES</h4><blockquote>The output from<i>vi</i>are text files that are identical tothe input files if no changes have been made to those filesby commands,with the exception that in all caseswhere a forced session termination (the<i><a href="ex.html">ex</a></i>commandq!)has not been issued prior to any write of the file,a trailingnewline characterwill be added to the last line of the file if one was notpresent in the input.</blockquote><h4><a name = "tag_001_014_2821"> </a>EXTENDED DESCRIPTION</h4><blockquote>Only the visual mode of the editor is described in this section.See the<i><a href="ex.html">ex</a></i>utility for additional editing capabilities used in<i>vi</i>.<p>The pathname of the file being edited by<i>vi</i>is the<i>current</i>file.The text of the file will be read into a<i>buffer</i>,and all editing changes will be performed in this buffer;changes will have no effect on the file until the buffer is written outexplicitly.Lines in the buffer may each be limited to{LINE_MAX}bytesand an error message may be displayed if the limit is exceededduring editing.<p>The<i>alternative</i>pathname is the name of the last file mentioned in aneditor command, or the previous current pathname if the last filementioned became the current file.When the character"%"appears in a pathname entered as part of a command argument,the character will be replaced by the current pathname;the character"#"will be replaced by the alternative pathname.The characters"%"and"#"can be escaped by preceding them with a backslash.<p>During initialisation, before thefirst file is read or any user commands from the terminal are processed,if the environment variable<i>EXINIT</i>is set, the editor will execute the<i><a href="ex.html">ex</a></i>commands contained in that variable.If the variable is not set,<i>vi</i>will attempt to read<i><a href="ex.html">ex</a></i>commands from the file<b>$HOME/.exrc</b>(the file<b>.exrc</b>in the directory referred to by the<i>HOME</i>environment variable).If and only if<i>EXINIT</i>or<b>$HOME/.exrc</b>sets the editor option<b>exrc</b>,<i>vi</i>finally will attempt to read<i><a href="ex.html">ex</a></i>commands from a file<b>.exrc</b>in the current directory.In the event that<i>EXINIT</i>is not set and the current directory is theuser's home directory, any<b>.exrc</b>file will only be processed once.No<b>.exrc</b>file will be read unless it is owned by thesame user ID as the effective user ID of the process.After any<b>.exrc</b>files are processed, any commands specified by the<b>-c</b>option will be processed.<p>After initialisation,<i>vi</i>will be in<i>command</i>mode;<i>input</i>mode can be entered by several commands used toinsert or change text.In input mode, anescape charactercan be used toreturn to command mode;other uses of theescape characterare described in<xref href=viterm><a href="#tag_001_014_2821_018">Terminate Command or Input Mode</a></xref>.The results of enteringnewline charactersin input mode are affected by the setting of the<b>autoindent</b>editor variable.<p>The last (bottom) line of the screen is used to displaythe input for search commands ("/" and "?"), for<i><a href="ex.html">ex</a></i>commands (":"), and system commands ("!").It is also used to report errors or displayinformational messages.The editor prompts for input for commands by displaying the command("/", "?", ":" or "!")at the beginning of the last line of the screen.All subsequent characters will be then taken as input untila line terminator is entered.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -