在linux中经常使用到man进行相关命令的查询和vim环境下文件的修改,使用好了相关快捷方式可以提高相应的操作速度和效率。

1、man帮助文档快捷键说明:


h  H                 Display this help.

  q  :q  Q  :Q  ZZ     Exit.
 ---------------------------------------------------------------------------

                           MOVING

  e  ^E  j  ^N  CR  *  Forward  one line   (or N lines).
  y  ^Y  k  ^K  ^P  *  Backward one line   (or N lines).
  f  ^F  ^V  SPACE  *  Forward  one window (or N lines).   行操作
  b  ^B  ESC-v      *  Backward one window (or N lines).
  z                 *  Forward  one window (and set window to N).
  w                 *  Backward one window (and set window to N).                        页操作
  ESC-SPACE         *  Forward  one window, but don't stop at end-of-file.
  d  ^D             *  Forward  one half-window (and set half-window to N).  
  u  ^U             *  Backward one half-window (and set half-window to N).                   
  ESC-)  RightArrow *  Left  one half screen width (or N positions).
  ESC-(  LeftArrow  *  Right one half screen width (or N positions).
  F                    Forward forever; like "tail -f".
  r  ^R  ^L            Repaint screen.
  R                    Repaint screen, discarding buffered input.
        ---------------------------------------------------
        Default "window" is the screen height.
        Default "half-window" is half of the screen height.
 ---------------------------------------------------------------------------
...skipping...
                  Forward scroll limit.
  -z [N]  ....  --window=[N]
                  Set size of window.
  -" [c[c]]  .  --quotes=[c[c]]
                  Set shell quote characters.
  -~  ........  --tilde
                  Don't display tildes after end of file.
  -# [N]  ....  --shift=[N]
                  Horizontal scroll amount (0 = one half screen width)

 ---------------------------------------------------------------------------

                          LINE EDITING

        These keys can be used to edit text being entered
        on the "command line" at the bottom of the screen.

 RightArrow                       ESC-l     Move cursor right one character.
 LeftArrow                        ESC-h     Move cursor left one character.
 CNTL-RightArrow  ESC-RightArrow  ESC-w     Move cursor right one word.
 CNTL-LeftArrow   ESC-LeftArrow   ESC-b     Move cursor left one word.
 HOME                             ESC-0     Move cursor to start of line.
 END                              ESC-$     Move cursor to end of line.
 BACKSPACE                                  Delete char to left of cursor.
 DELETE                           ESC-x     Delete char under cursor.
 CNTL-BACKSPACE   ESC-BACKSPACE             Delete word to left of cursor.
 CNTL-DELETE      ESC-DELETE      ESC-X     Delete word under cursor.
 CNTL-U           ESC (MS-DOS only)         Delete entire line.
 UpArrow                          ESC-k     Retrieve previous command line.
 DownArrow                        ESC-j     Retrieve next command line.
 TAB                                        Complete filename & cycle.
 SHIFT-TAB                        ESC-TAB   Complete filename & reverse cycle.

 CNTL-L                                     Complete filename, list all.

2、vim 快捷键说明

          VIM - main help file
                                                                                                                          k
      Move around:  Use the cursor keys, or "h" to go left,            h                 l                      上下左右移动光标
                    "j" to go down, "k" to go up, "l" to go right.                        j
Close this window:  Use ":q<Enter>".
   Get out of Vim:  Use ":qa!<Enter>" (careful, all changes are lost!).                                 :qa 不保存退出

Jump to a subject:  Position the cursor on a tag (e.g. |bars|) and hit CTRL-].
   With the mouse:  ":set mouse=a" to enable the mouse (in xterm or GUI).
                    Double-click the left mouse button on a tag, e.g. |bars|.
        Jump back:  Type CTRL-T or CTRL-O (repeat to go further back).

Get specific help:  It is possible to go directly to whatever you want help
                    on, by giving an argument to the |:help| command.
                    It is possible to further specify the context:
                                                        *help-context*
                          WHAT                  PREPEND    EXAMPLE      ~
                      Normal mode command      (nothing)   :help x
                      Visual mode command         v_       :help v_u                 可视化界面帮助文档

                      Insert mode command         i_       :help i_<Esc>         编辑界面帮助文档
                      Command-line command        :        :help :quit
                      Command-line editing        c_       :help c_<Del>
                      Vim command argument        -        :help -r
                      Option                      '        :help 'textwidth'
  Search for help:  Type ":help word", then hit CTRL-D to see matching
                    help entries for "word".

VIM stands for Vi IMproved.  Most of VIM was made by Bram Moolenaar, but only
through the help of many others.  See |credits|.
------------------------------------------------------------------------------
                                                *doc-file-list* *Q_ct*
BASIC:
|quickref|      Overview of the most common commands you will use
|tutor|         30 minutes training course for beginners
|copying|       About copyrights
|iccf|          Helping poor children in Uganda
|sponsor|       Sponsor Vim development, become a registered Vim user
|www|           Vim on the World Wide Web
|bugs|          Where to send bug reports

USER MANUAL: These files explain how to accomplish an editing task.

|usr_toc.txt|   Table Of Contents

Getting Started ~                                                   使用目录及文件
|usr_01.txt|  About the manuals
|usr_02.txt|  The first steps in Vim
|usr_03.txt|  Moving around
|usr_04.txt|  Making small changes
|usr_05.txt|  Set your settings
|usr_06.txt|  Using syntax highlighting
|usr_07.txt|  Editing more than one file
|usr_08.txt|  Splitting windows
|usr_09.txt|  Using the GUI
|usr_10.txt|  Making big changes
|usr_11.txt|  Recovering from a crash
|usr_12.txt|  Clever tricks
Editing Effectively ~
|usr_20.txt|  Typing command-line commands quickly
|usr_21.txt|  Go away and come back
|usr_22.txt|  Finding the file to edit
|usr_23.txt|  Editing other files
|usr_24.txt|  Inserting quickly
|usr_25.txt|  Editing formatted text
|usr_26.txt|  Repeating
|usr_27.txt|  Search commands and patterns
|usr_28.txt|  Folding
|usr_29.txt|  Moving through programs
|usr_30.txt|  Editing programs
|usr_31.txt|  Exploiting the GUI
|usr_32.txt|  The undo tree
Tuning Vim ~
|usr_40.txt|  Make new commands
|usr_41.txt|  Write a Vim script
|usr_42.txt|  Add new menus
|usr_43.txt|  Using filetypes
|usr_44.txt|  Your own syntax highlighted
|usr_45.txt|  Select your language

Making Vim Run ~
|usr_90.txt|  Installing Vim


REFERENCE MANUAL: These files explain every detail of Vim.      *reference_toc*

General subjects ~                                                                                                  普通主题
|intro.txt|     general introduction to Vim; notation used in help files
|help.txt|      overview and quick reference (this file)
|index.txt|     alphabetical index of all commands
|help-tags|     all the tags you can jump to (index of tags)

howto.txt|     how to do the most common editing tasks
|tips.txt|      various tips on using Vim
|message.txt|   (error) messages and explanations
|quotes.txt|    remarks from users of Vim
|todo.txt|      known problems and desired extensions
|develop.txt|   development of Vim
|debug.txt|     debugging Vim itself
|uganda.txt|    Vim distribution conditions and what to do with your money

Basic editing ~                                                                                                         基础编辑
|starting.txt|  starting Vim, Vim command arguments, initialisation
|editing.txt|   editing and writing files
|motion.txt|    commands for moving around
|scroll.txt|    scrolling the text in the window
|insert.txt|    Insert and Replace mode
|change.txt|    deleting and replacing text
|indent.txt|    automatic indenting for C and other languages
|undo.txt|      Undo and Redo
|repeat.txt|    repeating commands, Vim scripts and debugging

|visual.txt|    using the Visual mode (selecting a text area)
|various.txt|   various remaining commands
|recover.txt|   recovering from a crash

Advanced editing ~                                                                                            高级编辑
|cmdline.txt|   Command-line editing
|options.txt|   description of all options
|pattern.txt|   regexp patterns and search commands
|map.txt|       key mapping and abbreviations
|tagsrch.txt|   tags and special searches
|quickfix.txt|  commands for a quick edit-compile-fix cycle
|windows.txt|   commands for using multiple windows and buffers
|tabpage.txt|   commands for using multiple tab pages
|syntax.txt|    syntax highlighting
|spell.txt|     spell checking
|diff.txt|      working with two or three versions of the same file
|autocmd.txt|   automatically executing commands on an event
|filetype.txt|  settings done specifically for a type of file
|eval.txt|      expression evaluation, conditional commands

fold.txt|      hide (fold) ranges of lines

Special issues ~                                                                                                   特别注意
|print.txt|     printing
|remote.txt|    using Vim as a server or client
|term.txt|      using different terminals and mice
|digraph.txt|   list of available digraphs
|mbyte.txt|     multi-byte text support
|mlang.txt|     non-English language support
|arabic.txt|    Arabic language support and editing
|farsi.txt|     Farsi (Persian) editing
|hebrew.txt|    Hebrew language support and editing
|russian.txt|   Russian language support and editing
|ada.txt|       Ada (the programming language) support
|hangulin.txt|  Hangul (Korean) input mode
|rileft.txt|    right-to-left editing mode
GUI ~
|gui.txt|       Graphical User Interface (GUI)
|gui_w16.txt|   Windows 3.1 GUI
|gui_w32.txt|   Win32 GUI
|gui_x11.txt|   X11 GUI

Interfaces ~                                                                          接口操作
|if_cscop.txt|  using Cscope with Vim
|if_mzsch.txt|  MzScheme interface
|if_perl.txt|   Perl interface
|if_pyth.txt|   Python interface
|if_sniff.txt|  SNiFF+ interface
|if_tcl.txt|    Tcl interface
|if_ole.txt|    OLE automation interface for Win32
|if_ruby.txt|   Ruby interface
|debugger.txt|  Interface with a debugger
|workshop.txt|  Sun Visual Workshop interface
|netbeans.txt|  NetBeans External Editor interface
|sign.txt|      debugging signs
Versions ~
|vi_diff.txt|   Main differences between Vim and Vi
|version4.txt|  Differences between Vim version 3.0 and 4.x
|version5.txt|  Differences between Vim version 4.6 and 5.x
|version6.txt|  Differences between Vim version 5.7 and 6.x
|version7.txt|  Differences between Vim version 6.4 and 7.x
                                                *sys-file-list*
Remarks about specific systems ~
|os_390.txt|    OS/390 Unix
|os_amiga.txt|  Amiga
|os_beos.txt|   BeOS and BeBox
|os_dos.txt|    MS-DOS and MS-Windows NT/95 common items
|os_mac.txt|    Macintosh
|os_mint.txt|   Atari MiNT
|os_msdos.txt|  MS-DOS (plain DOS and DOS box under Windows)
|os_os2.txt|    OS/2

os_qnx.txt|    QNX
|os_risc.txt|   RISC-OS
|os_unix.txt|   Unix
|os_vms.txt|    VMS
|os_win32.txt|  MS-Windows 95/98/NT
                                                *standard-plugin-list*
Standard plugins ~
|pi_getscript.txt| Downloading latest version of Vim scripts
|pi_gzip.txt|      Reading and writing compressed files
|pi_netrw.txt|     Reading and writing files over a network
|pi_paren.txt|     Highlight matching parens
|pi_tar.txt|       Tar file explorer
|pi_vimball.txt|   Create a self-installing Vim script
|pi_zip.txt|       Zip archive explorer

LOCAL ADDITIONS:                                *local-additions*

------------------------------------------------------------------------------
*bars*          Bars example

Now that you've jumped here with CTRL-] or a double mouse click, you can use
CTRL-T, CTRL-O, g<RightMouse>, or <C-RightMouse> to go back to where you were.

Note that tags are within | characters, but when highlighting is enabled these
are hidden.  That makes it easier to read a command.

Anyway, you can use CTRL-] on any word, also when it is not within |, and Vim
will try to find help for it.

2.1 可视化界面帮助文档

                                                      *v_u*
{Visual}u               Make highlighted text lowercase (for {Visual} see
                        |Visual-mode|).  {not in Vi}

                                                        *gu* *lowercase*
gu{motion}              Make {motion} text lowercase. {not in Vi}

gugu                                                    *gugu* *guu*
guu                     Make current line lowercase. {not in Vi}.

                                                        *g?* *rot13*
g?{motion}              Rot13 encode {motion} text. {not in Vi}

                                                        *v_g?*
{Visual}g?              Rot13 encode the highlighted text (for {Visual} see
                        |Visual-mode|).  {not in Vi}

g?g?                                                    *g?g?* *g??*
g??                     Rot13 encode current line. {not in Vi}.


Adding and subtracting ~
                                                        *CTRL-A*
CTRL-A                  Add [count] to the number or alphabetic character at
                        or after the cursor.  {not in Vi}

                                                        *CTRL-X*
CTRL-X                  Subtract [count] from the number or alphabetic
                        character at or after the cursor.  {not in Vi}

The CTRL-A and CTRL-X commands work for (signed) decimal numbers, unsigned
octal and hexadecimal numbers and alphabetic characters.  This depends on the
'nrformats' option.
- When 'nrformats' includes "octal", Vim considers numbers starting with a '0'
  to be octal, unless the number includes a '8' or '9'.  Other numbers are
  decimal and may have a preceding minus sign.
  If the cursor is on a number, the commands apply to that number; otherwise
  Vim uses the number to the right of the cursor.
- When 'nrformats' includes "hex", Vim assumes numbers starting with '0x' or
  '0X' are hexadecimal.  The case of the rightmost letter in the number
  determines the case of the resulting hexadecimal number.  If there is no
  letter in the current number, Vim uses the previously detected case.
- When 'nrformats' includes "alpha", Vim will change the alphabetic character
  under or after the cursor.  This is useful to make lists with an alphabetic
  index.

For numbers with leading zeros (including all octal and hexadecimal numbers),
Vim preserves the number of characters in the number when possible.  CTRL-A on
"0077" results in "0100", CTRL-X on "0x100" results in "0x0ff".
There is one exception: When a number that starts with a zero is found not to
be octal (it contains a '8' or '9'), but 'nrformats' does include "octal",
leading zeros are removed to avoid that the result may be recognized as an
octal number.

Note that when 'nrformats' includes "octal", decimal numbers with leading
zeros cause mistakes, because they can be confused with octal numbers.

The CTRL-A command is very useful in a macro.  Example: Use the following
steps to make a numbered list.

1. Create the first list entry, make sure it starts with a number.
2. qa        - start recording into register 'a'
3. Y         - yank the entry
4. p         - put a copy of the entry below the first one
5. CTRL-A    - increment the number
6. q         - stop recording
7. <count>@a - repeat the yank, put and increment <count> times


SHIFTING LINES LEFT OR RIGHT                            *shift-left-right*

                                                        *<*
<{motion}               Shift {motion} lines one 'shiftwidth' leftwards.

                                                        *<<*
<<                      Shift [count] lines one 'shiftwidth' leftwards.

                                                        *v_<*
{Visual}[count]<        Shift the highlighted lines [count] 'shiftwidth'
                        leftwards (for {Visual} see |Visual-mode|).  {not in
                        Vi}

                                                        *>*
 >{motion}              Shift {motion} lines one 'shiftwidth' rightwards.

                                                        *>>*
 >>                     Shift [count] lines one 'shiftwidth' rightwards.

                                                        *v_>*
{Visual}[count]>        Shift the highlighted lines [count] 'shiftwidth'
                        rightwards (for {Visual} see |Visual-mode|).  {not in
                        Vi}

                                                        *:<*
:[range]<               Shift [range] lines one 'shiftwidth' left.  Repeat '<'
                        for shifting multiple 'shiftwidth's.

:[range]< {count}       Shift {count} lines one 'shiftwidth' left, starting
                        with [range] (default current line |cmdline-ranges|).
                        Repeat '<' for shifting multiple 'shiftwidth's.

:[range]le[ft] [indent] left align lines in [range].  Sets the indent in the
                        lines to [indent] (default 0).  {not in Vi}

                                                        *:>*
:[range]> [flags]       Shift {count} [range] lines one 'shiftwidth' right.
                        Repeat '>' for shifting multiple 'shiftwidth's.
                        See |ex-flags| for [flags].

:[range]> {count} [flags]
                        Shift {count} lines one 'shiftwidth' right, starting
                        with [range] (default current line |cmdline-ranges|).
                        Repeat '>' for shifting multiple 'shiftwidth's.
                        See |ex-flags| for [flags].

The ">" and "<" commands are handy for changing the indentation within
programs.  Use the 'shiftwidth' option to set the size of the white space
which these commands insert or delete.  Normally the 'shiftwidth' option is 8,
but you can set it to, say, 3 to make smaller indents.  The shift leftwards
stops when there is no indent.  The shift right does not affect empty lines.

If the 'shiftround' option is on, the indent is rounded to a multiple of
'shiftwidth'.

If the 'smartindent' option is on, or 'cindent' is on and 'cinkeys' contains
'#', shift right does not affect lines starting with '#' (these are supposed
to be C preprocessor lines that must stay in column 1).

When the 'expandtab' option is off (this is the default) Vim uses <Tab>s as
much as possible to make the indent.  You can use ">><<" to replace an indent
made out of spaces with the same indent made out of <Tab>s (and a few spaces
if necessary).  If the 'expandtab' option is on, Vim uses only spaces.  Then
you can use ">><<" to replace <Tab>s in the indent by spaces (or use
":retab!").

To move a line several 'shiftwidth's, use Visual mode or the ":" commands.
For example: >
        Vjj4>           move three lines 4 indents to the right
        :<<<            move current line 3 indents to the left
        :>> 5           move 5 lines 2 indents to the right
        :5>>            move line 5 2 indents to the right

==============================================================================
4. Complex changes                                      *complex-change*

4.1 Filter commands                                     *filter*

A filter is a program that accepts text at standard input, changes it in some
way, and sends it to standard output.  You can use the commands below to send
some text through a filter, so that it is replace by the filter output.
Examples of filters are "sort", which sorts lines alphabetically, and
"indent", which formats C program files (you need a version of indent that
works like a filter; not all versions do).  The 'shell' option specifies the
shell Vim uses to execute the filter command (See also the 'shelltype'
option).  You can repeat filter commands with ".".  Vim does not recognize a
comment (starting with '"') after the ":!" command.

                                                        *!*
!{motion}{filter}       Filter {motion} text lines through the external
                        program {filter}.

                                                        *!!*
!!{filter}              Filter [count] lines through the external program
                        {filter}.

                                                        *v_!*
{Visual}!{filter}       Filter the highlighted lines through the external
                        program {filter} (for {Visual} see |Visual-mode|).
                        {not in Vi}

:{range}![!]{filter} [!][arg]                           *:range!*
                        Filter {range} lines through the external program
                        {filter}.  Vim replaces the optional bangs with the
                        latest given command and appends the optional [arg].
                        Vim saves the output of the filter command in a
                        temporary file and then reads the file into the
                        buffer.  Vim uses the 'shellredir' option to redirect
                        the filter output to the temporary file.
                        However, if the 'shelltemp' option is off then pipes
                        are used when possible (on Unix).
                        When the 'R' flag is included in 'cpoptions' marks in
                        the filtered lines are deleted, unless the
                        |:keepmarks| command is used.  Example: >
                                :keepmarks '<,'>!sort
<                       When the number of lines after filtering is less than
                        before, marks in the missing lines are deleted anyway.

                                                        *=*
={motion}               Filter {motion} lines through the external program
                        given with the 'equalprg' option.  When the 'equalprg'
                        option is empty (this is the default), use the
                        internal formatting function |C-indenting|.  But when
                        'indentexpr' is not empty, it will be used instead
                        |indent-expression|.

                                                        *==*
==                      Filter [count] lines like with ={motion}.

                                                        *v_=*
{Visual}=               Filter the highlighted lines like with ={motion}.
                        {not in Vi}


4.2 Substitute                                          *:substitute*
                                                        *:s* *:su*
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
                        For each line in [range] replace a match of {pattern}
                        with {string}.
                        For the {pattern} see |pattern|.
                        {string} can be a literal string, or something
                        special; see |sub-replace-special|.
                        When [range] and [count] are omitted, replace in the
                        current line only.
                        When [count] is given, replace in [count] lines,
                        starting with the last line in [range].  When [range]
                        is omitted start in the current line.
                        Also see |cmdline-ranges|.
                        See |:s_flags| for [flags].

:[range]s[ubstitute] [flags] [count]
:[range]&[&][flags] [count]                                     *:&*
                        Repeat last :substitute with same search pattern and
                        substitute string, but without the same flags.  You
                        may add [flags], see |:s_flags|.
                        Note that after ":substitute" the '&' flag can't be
                        used, it's recognized as a pattern separator.
                        The space between ":substitute" and the 'c', 'g' and
                        'r' flags isn't required, but in scripts it's a good
                        idea to keep it to avoid confusion.

:[range]~[&][flags] [count]                                     *:~*
                        Repeat last substitute with same substitute string
                        but with last used search pattern.  This is like
                        ":&r".  See |:s_flags| for [flags].

                                                                *&*
&                       Synonym for ":s//~/" (repeat last substitute).  Note
                        that the flags are not remembered, thus it might
                        actually work differently.  You can use ":&&" to keep
                        the flags.

                                                                *g&*
g&                      Synonym for ":%s//~/&" (repeat last substitute on all
                        lines with the same flags).
                        Mnemonic: global substitute. {not in Vi}

                                                *:snomagic* *:sno*
:[range]sno[magic] ...  Same as ":substitute", but always use 'nomagic'.
                        {not in Vi}

                                                *:smagic* *:sm*
:[range]sm[agic] ...    Same as ":substitute", but always use 'magic'.
                        {not in Vi}

                                                        *:s_flags*
The flags that you can use for the substitute commands:

[&]     Must be the first one: Keep the flags from the previous substitute
        command.  Examples: >
                :&&
                :s/this/that/&
<       Note that ":s" and ":&" don't keep the flags.
        {not in Vi}

[c]     Confirm each substitution.  Vim highlights the matching string (with
        |hl-IncSearch|).  You can type:                         *:s_c*
            'y'     to substitute this match
            'l'     to substitute this match and then quit ("last")
            'n'     to skip this match
            <Esc>   to quit substituting
            'a'     to substitute this and all remaining matches {not in Vi}
            'q'     to quit substituting {not in Vi}
            CTRL-E  to scroll the screen up {not in Vi, not available when
                        compiled without the +insert_expand feature}
            CTRL-Y  to scroll the screen down {not in Vi, not available when
                        compiled without the +insert_expand feature}
        If the 'edcompatible' option is on, Vim remembers the [c] flag and
        toggles it each time you use it, but resets it when you give a new
        search pattern.
        {not in Vi: highlighting of the match, other responses than 'y' or 'n'}

[e]     When the search pattern fails, do not issue an error message and, in
        particular, continue in maps as if no error occurred.  This is most
        useful to prevent the "No match" error from breaking a mapping.  Vim
        does not suppress the following error messages, however:
                Regular expressions can't be delimited by letters
                \ should be followed by /, ? or &
                No previous substitute regular expression
                Trailing characters
                Interrupted
        {not in Vi}

[g]     Replace all occurrences in the line.  Without this argument,
        replacement occurs only for the first occurrence in each line.  If
        the 'edcompatible' option is on, Vim remembers this flag and toggles
        it each time you use it, but resets it when you give a new search
        pattern.  If the 'gdefault' option is on, this flag is on by default
        and the [g] argument switches it off.

[i]     Ignore case for the pattern.  The 'ignorecase' and 'smartcase' options
        are not used.
        {not in Vi}

[I]     Don't ignore case for the pattern.  The 'ignorecase' and 'smartcase'
        options are not used.
        {not in Vi}

[n]     Report the number of matches, do not actually substitute.  The [c]
        flag is ignored.  The matches are reported as if 'report' is zero.
        Useful to |count-items|.

[p]     Print the line containing the last substitute.

[#]     Like [p] and prepend the line number.

[l]     Like [p] but print the text like |:list|.

[r]     Only useful in combination with ":&" or ":s" without arguments.  ":&r"
        works the same way as ":~":  When the search pattern is empty, use the
        previously used search pattern instead of the search pattern from the
        last substitute or ":global".  If the last command that did a search
        was a substitute or ":global", there is no effect.  If the last
        command was a search command such as "/", use the pattern from that
        command.
        For ":s" with an argument this already happens: >
                :s/blue/red/
                /green
                :s//red/   or  :~   or  :&r
<       The last commands will replace "green" with "red". >
                :s/blue/red/
                /green
                :&
<       The last command will replace "blue" with "red".
        {not in Vi}

Note that there is no flag to change the "magicness" of the pattern.  A
different command is used instead.  The reason is that the flags can only be
found by skipping the pattern, and in order to skip the pattern the
"magicness" must be known.  Catch 22!

If the {pattern} for the substitute command is empty, the command uses the
pattern from the last substitute or ":global" command.  With the [r] flag, the
command uses the pattern from the last substitute, ":global", or search
command.

If the {string} is omitted the substitute is done as if it's empty.  Thus the
matched pattern is deleted.  The separator after {pattern} can also be left
out then.  Example: >
        :%s/TESTING
This deletes "TESTING" from all lines, but only one per line.

For compatibility with Vi these two exceptions are allowed:
"\/{string}/" and "\?{string}?" do the same as "//{string}/r".
"\&{string}&" does the same as "//{string}/".
                                                        *E146*
Instead of the '/' which surrounds the pattern and replacement string, you
can use any other single-byte character, but not an alphanumeric character,
'\', '"' or '|'.  This is useful if you want to include a '/' in the search
pattern or replacement string.  Example: >
        :s+/+//+

For the definition of a pattern, see |pattern|.

                                        *sub-replace-special* *:s\=*
When the {string} starts with "\=" it is evaluated as an expression, see
|sub-replace-expression|.  You can use that for any special characters.
Otherwise these characters in {string} have a special meaning:
                                                                *:s%*
When {string} is equal to "%" and '/' is included with the 'cpoptions' option,
then the {string} of the previous substitute command is used. |cpo-/|

magic   nomagic   action    ~
  &       \&      replaced with the whole matched pattern            *s/\&*
 \&        &      replaced with &
      \0          replaced with the whole matched pattern          *\0* *s/\0*
      \1          replaced with the matched pattern in the first
                  pair of ()                                         *s/\1*
      \2          replaced with the matched pattern in the second
                  pair of ()                                         *s/\2*
      ..          ..                                                 *s/\3*
      \9          replaced with the matched pattern in the ninth
                  pair of ()                                         *s/\9*
  ~       \~      replaced with the {string} of the previous
                  substitute                                         *s~*
 \~        ~      replaced with ~                                    *s/\~*
      \u          next character made uppercase                      *s/\u*
      \U          following characters made uppercase, until \E      *s/\U*
      \l          next character made lowercase                      *s/\l*
      \L          following characters made lowercase, until \E      *s/\L*
      \e          end of \u, \U, \l and \L (NOTE: not <Esc>!)        *s/\e*
      \E          end of \u, \U, \l and \L                           *s/\E*
      <CR>        split line in two at this point
                  (Type the <CR> as CTRL-V <Enter>)                  *s<CR>*
      \r          idem                                               *s/\r*
      \<CR>       insert a carriage-return (CTRL-M)
                  (Type the <CR> as CTRL-V <Enter>)                  *s/\<CR>*
      \n          insert a <NL> (<NUL> in the file)
                  (does NOT break the line)                          *s/\n*
      \b          insert a <BS>                                      *s/\b*
      \t          insert a <Tab>                                     *s/\t*
      \\          insert a single backslash                          *s/\\*
      \x          where x is any character not mentioned above:
                  Reserved for future expansion

Examples: >
  :s/a\|b/xxx\0xxx/g             modifies "a b"      to "xxxaxxx xxxbxxx"
  :s/\([abc]\)\([efg]\)/\2\1/g   modifies "af fa bg" to "fa fa gb"
  :s/abcde/abc^Mde/              modifies "abcde"    to "abc", "de" (two lines)
  :s/$/\^M/                      modifies "abcde"    to "abcde^M"
  :s/\w\+/\u\0/g                 modifies "bla bla"  to "Bla Bla"

Note: In previous versions CTRL-V was handled in a special way.  Since this is
not Vi compatible, this was removed.  Use a backslash instead.

command         text    result ~
:s/aa/a^Ma/     aa      a<line-break>a
:s/aa/a\^Ma/    aa      a^Ma
:s/aa/a\\^Ma/   aa      a\<line-break>a

(you need to type CTRL-V <CR> to get a ^M here)

The numbering of "\1", "\2" etc. is done based on which "\(" comes first in
the pattern (going left to right).  When a parentheses group matches several
times, the last one will be used for "\1", "\2", etc.  Example: >
  :s/\(\(a[a-d] \)*\)/\2/      modifies "aa ab x" to "ab x"

When using parentheses in combination with '|', like in \([ab]\)\|\([cd]\),
either the first or second pattern in parentheses did not match, so either
\1 or \2 is empty.  Example: >
  :s/\([ab]\)\|\([cd]\)/\1x/g   modifies "a b c d"  to "ax bx x x"
<

Substitute with an expression                   *sub-replace-expression*
                                                *sub-replace-\=*
When the substitute string starts with "\=" the remainder is interpreted as an
expression.  This does not work recursively: a substitute() function inside
the expression cannot use "\=" for the substitute string.

The special meaning for characters as mentioned at |sub-replace-special| does
not apply except "<CR>", "\<CR>" and "\\".  Thus in the result of the
expression you need to use two backslashes get one, put a backslash before a
<CR> you want to insert and use a <CR> without a backslash where you want to
break the line.

For convenience a <NL> character is also used as a line break.  Prepend a
backslash to get a real <NL> character (which will be a NUL in the file).

When the result is a |List| then the items are joined with separating line
breaks.  Thus each item becomes a line, except that they can contain line
breaks themselves.

The whole matched text can be accessed with "submatch(0)".  The text matched
with the first pair of () with "submatch(1)".  Likewise for further
sub-matches in ().

Be careful: The separation character must not appear in the expression!
Consider using a character like "@" or ":".  There is no problem if the result
of the expression contains the separation character.

Examples: >
        :s@\n@\="\r" . expand("$HOME") . "\r"@
This replaces an end-of-line with a new line containing the value of $HOME. >

        s/E/\="\<Char-0x20ac>"/g
This replaces 'E' characters with an euro sign. Read more in |<Char->|.


4.3 Search and replace                                  *search-replace*

                                                        *:pro* *:promptfind*
:promptf[ind] [string]
                        Put up a Search dialog.  When [string] is given, it is
                        used as the initial search string.
                        {only for Win32, Motif and GTK GUI}

                                                *:promptr* *:promptrepl*
:promptr[epl] [string]
                        Put up a Search/Replace dialog.  When [string] is
                        given, it is used as the initial search string.
                        {only for Win32, Motif and GTK GUI}


4.4 Changing tabs                                       *change-tabs*
                                                        *:ret* *:retab*
:[range]ret[ab][!] [new_tabstop]
                        Replace all sequences of white-space containing a
                        <Tab> with new strings of white-space using the new
                        tabstop value given.  If you do not specify a new
                        tabstop size or it is zero, Vim uses the current value
                        of 'tabstop'.


The current value of 'tabstop' is always used to
                        compute the width of existing tabs.
                        With !, Vim also replaces strings of only normal
                        spaces with tabs where appropriate.
                        With 'expandtab' on, Vim replaces all tabs with the
                        appropriate number of spaces.
                        This command sets 'tabstop' to the new value given,
                        and if performed on the whole file, which is default,
                        should not make any visible change.
                        Careful: This command modifies any <Tab> characters
                        inside of strings in a C program.  Use "\t" to avoid
                        this (that's a good habit anyway).
                        ":retab!" may also change a sequence of spaces by
                        <Tab> characters, which can mess up a printf().
                        {not in Vi}
                        Not available when |+ex_extra| feature was disabled at
                        compile time.

                                                        *retab-example*
Example for using autocommands and ":retab" to edit a file which is stored
with tabstops at 8 but edited with tabstops set at 4.  Warning: white space
inside of strings can change!  Also see 'softtabstop' option. >

  :auto BufReadPost     *.xx    retab! 4
  :auto BufWritePre     *.xx    retab! 8
  :auto BufWritePost    *.xx    retab! 4
  :auto BufNewFile      *.xx    set ts=4

==============================================================================
5. Copying and moving text                              *copy-move*

                                                        *quote*
"{a-zA-Z0-9.%#:-"}      Use register {a-zA-Z0-9.%#:-"} for next delete, yank
                        or put (use uppercase character to append with
                        delete and yank) ({.%#:} only work with put).

                                                        *:reg* *:registers*
:reg[isters]            Display the contents of all numbered and named
                        registers.  {not in Vi}

:reg[isters] {arg}      Display the contents of the numbered and named
                        registers that are mentioned in {arg}.  For example: >
                                :dis 1a
<                       to display registers '1' and 'a'.  Spaces are allowed
                        in {arg}.  {not in Vi}

                                                        *:di* *:display*
:di[splay] [arg]        Same as :registers.  {not in Vi}

                                                        *y* *yank*
["x]y{motion}           Yank {motion} text [into register x].  When no
                        characters are to be yanked (e.g., "y0" in column 1),
                        this is an error when 'cpoptions' includes the 'E'
                        flag.

                                                        *yy*
["x]yy                  Yank [count] lines [into register x] |linewise|.

                                                        *Y*
["x]Y                   yank [count] lines [into register x] (synonym for
                        yy, |linewise|).  If you like "Y" to work from the
                        cursor to the end of line (which is more logical,
                        but not Vi-compatible) use ":map Y y$".

                                                        *v_y*
{Visual}["x]y           Yank the highlighted text [into register x] (for
                        {Visual} see |Visual-mode|).  {not in Vi}

                                                        *v_Y*
{Visual}["x]Y           Yank the highlighted lines [into register x] (for
                        {Visual} see |Visual-mode|).  {not in Vi}

                                                        *:y* *:yank*
:[range]y[ank] [x]      Yank [range] lines [into register x].

:[range]y[ank] [x] {count}
                        Yank {count} lines, starting with last line number
                        in [range] (default: current line |cmdline-ranges|),
                        [into register x].

                                                        *p* *put* *E353*
["x]p                   Put the text [from register x] after the cursor
                        [count] times.  {Vi: no count}

                                                        *P*
["x]P                   Put the text [from register x] before the cursor
                        [count] times.  {Vi: no count}

                                                        *<MiddleMouse>*
["x]<MiddleMouse>       Put the text from a register before the cursor [count]
                        times.  Uses the "* register, unless another is
                        specified.
                        Leaves the cursor at the end of the new text.
                        Using the mouse only works when 'mouse' contains 'n'
                        or 'a'.
                        {not in Vi}
                        If you have a scrollwheel and often accidentally paste
                        text, you can use these mappings to disable the
                        pasting with the middle mouse button: >
                                :map <MiddleMouse> <Nop>
                                :imap <MiddleMouse> <Nop>
<                       You might want to disable the multi-click versions
                        too, see |double-click|.

                                                        *gp*
["x]gp                  Just like "p", but leave the cursor just after the new
                        text.  {not in Vi}

                                                        *gP*
["x]gP                  Just like "P", but leave the cursor just after the new
                        text.  {not in Vi}

                                                        *:pu* *:put*
:[line]pu[t] [x]        Put the text [from register x] after [line] (default
                        current line).  This always works |linewise|, thus
                        this command can be used to put a yanked block as new
                        lines.
                        The cursor is left on the first non-blank in the last
                        new line.
                        The register can also be '=' followed by an optional
                        expression.  The expression continues until the end of
                        the command.  You need to escape the '|' and '"'
                        characters to prevent them from terminating the
                        command.  Example: >
                                :put ='path' . \",/test\"
<                       If there is no expression after '=', Vim uses the
                        previous expression.  You can see it with ":dis =".

:[line]pu[t]! [x]       Put the text [from register x] before [line] (default
                        current line).

["x]]p              or                                  *]p* *]<MiddleMouse>*
["x]]<MiddleMouse>      Like "p", but adjust the indent to the current line.
                        Using the mouse only works when 'mouse' contains 'n'
                        or 'a'.  {not in Vi}

["x][P              or                                  *[P*
["x]]P              or                                  *]P*
["x][p              or                                  *[p* *[<MiddleMouse>*
["x][<MiddleMouse>      Like "P", but adjust the indent to the current line.
                        Using the mouse only works when 'mouse' contains 'n'
                        or 'a'.  {not in Vi}

You can use these commands to copy text from one place to another.  Do this
by first getting the text into a register with a yank, delete or change
command, then inserting the register contents with a put command.  You can
also use these commands to move text from one file to another, because Vim
preserves all registers when changing buffers (the CTRL-^ command is a quick
way to toggle between two files).

                                *linewise-register* *characterwise-register*
You can repeat the put commands with "." (except for :put) and undo them.  If
the command that was used to get the text into the register was |linewise|,
Vim inserts the text below ("p") or above ("P") the line where the cursor is.
Otherwise Vim inserts the text after ("p") or before ("P") the cursor.  With
the ":put" command, Vim always inserts the text in the next line.  You can
exchange two characters with the command sequence "xp".  You can exchange two
lines with the command sequence "ddp".  You can exchange two words with the
command sequence "deep" (start with the cursor in the blank space before the
first word).  You can use the "']" or "`]" command after the put command to
move the cursor to the end of the inserted text, or use "'[" or "`[" to move
the cursor to the start.

                                                *put-Visual-mode* *v_p* *v_P*
When using a put command like |p| or |P| in Visual mode, Vim will try to
replace the selected text with the contents of the register.  Whether this
works well depends on the type of selection and the type of the text in the
register.  With blockwise selection it also depends on the size of the block
and whether the corners are on an existing character.  (Implementation detail:
it actually works by first putting the register after the selection and then
deleting the selection.)

                                                        *blockwise-register*
If you use a blockwise Visual mode command to get the text into the register,
the block of text will be inserted before ("P") or after ("p") the cursor
column in the current and next lines.  Vim makes the whole block of text start
in the same column.  Thus the inserted text looks the same as when it was
yanked or deleted.  Vim may replace some <Tab> characters with spaces to make
this happen.  However, if the width of the block is not a multiple of a <Tab>
width and the text after the inserted block contains <Tab>s, that text may be
misaligned.

Note that after a characterwise yank command, Vim leaves the cursor on the
first yanked character that is closest to the start of the buffer.  This means
that "yl" doesn't move the cursor, but "yh" moves the cursor one character
left.
Rationale:      In Vi the "y" command followed by a backwards motion would
                sometimes not move the cursor to the first yanked character,
                because redisplaying was skipped.  In Vim it always moves to
                the first character, as specified by Posix.
With a linewise yank command the cursor is put in the first line, but the
column is unmodified, thus it may not be on the first yanked character.

There are nine types of registers:                      *registers* *E354*
1. The unnamed register ""
2. 10 numbered registers "0 to "9
3. The small delete register "-
4. 26 named registers "a to "z or "A to "Z
5. four read-only registers ":, "., "% and "#
6. the expression register "=
7. The selection and drop registers "*, "+ and "~
8. The black hole register "_
9. Last search pattern register "/

1. Unnamed register ""                          *quote_quote* *quotequote*
Vim fills this register with text deleted with the "d", "c", "s", "x" commands
or copied with the yank "y" command, regardless of whether or not a specific
register was used (e.g.  "xdd).  This is like the unnamed register is pointing
to the last used register.  An exception is the '_' register: "_dd does not
store the deleted text in any register.
Vim uses the contents of the unnamed register for any put command (p or P)
which does not specify a register.  Additionally you can access it with the
name '"'.  This means you have to type two double quotes.  Writing to the ""
register writes to register "0.
{Vi: register contents are lost when changing files, no '"'}

2. Numbered registers "0 to "9          *quote_number* *quote0* *quote1*
                                        *quote2* *quote3* *quote4* *quote9*
Vim fills these registers with text from yank and delete commands.
   Numbered register 0 contains the text from the most recent yank command,
unless the command specified another register with ["x].
   Numbered register 1 contains the text deleted by the most recent delete or
change command, unless the command specified another register or the text is
less than one line (the small delete register is used then).  An exception is
made for the delete operator with these movement commands: |%|, |(|, |)|, |`|,
|/|, |?|, |n|, |N|, |{| and |}|.  Register "1 is always used then (this is Vi
compatible).  The "- register is used as well if the delete is within a line.
   With each successive deletion or change, Vim shifts the previous contents
of register 1 into register 2, 2 into 3, and so forth, losing the previous
contents of register 9.
{Vi: numbered register contents are lost when changing files; register 0 does
not exist}

3. Small delete register "-                             *quote_-* *quote-*
This register contains text from commands that delete less than one line,
except when the command specifies a register with ["x].
{not in Vi}

4. Named registers "a to "z or "A to "Z                 *quote_alpha* *quotea*
Vim fills these registers only when you say so.  Specify them as lowercase
letters to replace their previous contents or as uppercase letters to append
to their previous contents.  When the '>' flag is present in 'cpoptions' then
a line break is inserted before the appended text.

5. Read-only registers ":, "., "% and "#
These are '%', '#', ':' and '.'.  You can use them only with the "p", "P",
and ":put" commands and with CTRL-R.  {not in Vi}
                                                *quote_.* *quote.* *E29*
        ".      Contains the last inserted text (the same as what is inserted
                with the insert mode commands CTRL-A and CTRL-@).  Note: this
                doesn't work with CTRL-R on the command-line.  It works a bit
                differently, like inserting the text instead of putting it
                ('textwidth' and other options affect what is inserted).
                                                        *quote_%* *quote%*
        "%      Contains the name of the current file.
                                                        *quote_#* *quote#*
        "#      Contains the name of the alternate file.
                                                *quote_:* *quote:* *E30*
        ":      Contains the most recent executed command-line.  Example: Use
                "@:" to repeat the previous command-line command.
                The command-line is only stored in this register when at least
                one character of it was typed.  Thus it remains unchanged if
                the command was completely from a mapping.
                {not available when compiled without the |+cmdline_hist|
                feature}

6. Expression register "=                       *quote_=* *quote=* *@=*
This is not really a register that stores text, but is a way to use an
expression in commands which use a register.  The expression register is
read-only; you cannot put text into it.  After the '=', the cursor moves to
the command-line, where you can enter any expression (see |expression|).  All
normal command-line editing commands are available, including a special
history for expressions.  When you end the command-line by typing <CR>, Vim
computes the result of the expression.  If you end it with <Esc>, Vim abandons
the expression.  If you do not enter an expression, Vim uses the previous
expression (like with the "/" command).  The expression must evaluate to a
string.  If the result is a number it's turned into a string.  A List,
Dictionary or FuncRef results in an error message (use string() to convert).
If the "= register is used for the "p" command, the string is split up at <NL>
characters.  If the string ends in a <NL>, it is regarded as a linewise
register.  {not in Vi}

7. Selection and drop registers "*, "+ and "~
Use these register for storing and retrieving the selected text for the GUI.
See |quotestar| and |quoteplus|.  When the clipboard is not available or not
working, the unnamed register is used instead.  For Unix systems the clipboard
is only available when the |+xterm_clipboard| feature is present.  {not in Vi}

Note that there is only a distinction between "* and "+ for X11 systems.  For
an explanation of the difference, see |x11-selection|.  Under MS-Windows, use
of "* and "+ is actually synonymous and refers to the |gui-clipboard|.

                                                *quote_~* *quote~* *<Drop>*
The read-only "~ register stores the dropped text from the last drag'n'drop
operation.  When something has been dropped onto Vim, the "~ register is
filled in and the <Drop> pseudo key is sent for notification.  You can remap
this key if you want; the default action (for all modes) is to insert the
contents of the "~ register at the cursor position.  {not in Vi}
{only available when compiled with the |+dnd| feature, currently only with the
GTK GUI}

Note: The "~ register is only used when dropping plain text onto Vim.
Drag'n'drop of URI lists is handled internally.

8. Black hole register "_                               *quote_*
When writing to this register, nothing happens.  This can be used to delete
text without affecting the normal registers.  When reading from this register,
nothing is returned.  {not in Vi}

9. Last search pattern register "/                      *quote_/* *quote/*
Contains the most recent search-pattern.  This is used for "n" and 'hlsearch'.
It is writable with ":let", you can change it to have 'hlsearch' highlight
other matches without actually searching.  You can't yank or delete into this
register.  {not in Vi}

                                                        *@/*
You can write to a register with a ":let" command |:let-@|.  Example: >
        :let @/ = "the"

If you use a put command without specifying a register, Vim uses the register
that was last filled (this is also the contents of the unnamed register).  If
you are confused, use the ":dis" command to find out what Vim will put (this
command displays all named and numbered registers; the unnamed register is
labelled '"').

The next three commands always work on whole lines.

:[range]co[py] {address}                                *:co* *:copy*
                        Copy the lines given by [range] to below the line
                        given by {address}.

                                                        *:t*
:t                      Synonym for copy.

:[range]m[ove] {address}                        *:m* *:mo* *:move* *E134*
                        Move the lines given by [range] to below the line
                        given by {address}.

==============================================================================
6. Formatting text                                      *formatting*

:[range]ce[nter] [width]                                *:ce* *:center*
                        Center lines in [range] between [width] columns
                        (default 'textwidth' or 80 when 'textwidth' is 0).
                        {not in Vi}
                        Not available when |+ex_extra| feature was disabled at
                        compile time.

:[range]ri[ght] [width]                                 *:ri* *:right*
                        Right-align lines in [range] at [width] columns
                        (default 'textwidth' or 80 when 'textwidth' is 0).
                        {not in Vi}
                        Not available when |+ex_extra| feature was disabled at
                        compile time.

                                                        *:le* *:left*
:[range]le[ft] [indent]
                        Left-align lines in [range].  Sets the indent in the
                        lines to [indent] (default 0).  {not in Vi}
                        Not available when |+ex_extra| feature was disabled at
                        compile time.

                                                        *gq*
gq{motion}              Format the lines that {motion} moves over.
                        Formatting is done with one of three methods:
                        1. If 'formatexpr' is not empty the expression is
                           evaluated.  This can differ for each buffer.
                        2. If 'formatprg' is not empty an external program
                           is used.
                        3. Otherwise formatting is done internally.

                        In the third case the 'textwidth' option controls the
                        length of each formatted line (see below).
                        If the 'textwidth' option is 0, the formatted line
                        length is the screen width (with a maximum width of
                        79).
                        The 'formatoptions' option controls the type of
                        formatting |fo-table|.
                        The cursor is left on the first non-blank of the last
                        formatted line.
                        NOTE: The "Q" command formerly performed this
                        function.  If you still want to use "Q" for
                        formatting, use this mapping: >
                                :nnoremap Q gq

gqgq                                                    *gqgq* *gqq*
gqq                     Format the current line.  {not in Vi}

                                                        *v_gq*
{Visual}gq              Format the highlighted text.  (for {Visual} see
                        |Visual-mode|).  {not in Vi}

                                                        *gw*
gw{motion}              Format the lines that {motion} moves over.  Similar to
                        |gq| but puts the cursor back at the same position in
                        the text.  However, 'formatprg' and 'formatexpr' are
                        not used.  {not in Vi}

gwgw                                                    *gwgw* *gww*
gww                     Format the current line as with "gw".  {not in Vi}

                                                        *v_gw*
{Visual}gw              Format the highlighted text as with "gw".  (for
                        {Visual} see |Visual-mode|).  {not in Vi}

Example: To format the current paragraph use:                   *gqap*  >
        gqap

The "gq" command leaves the cursor in the line where the motion command takes
the cursor.  This allows you to repeat formatting repeated with ".".  This
works well with "gqj" (format current and next line) and "gq}" (format until
end of paragraph).  Note: When 'formatprg' is set, "gq" leaves the cursor on
the first formatted line (as with using a filter command).

If you want to format the current paragraph and continue where you were, use: >
        gwap
If you always want to keep paragraphs formatted you may want to add the 'a'
flag to 'formatoptions'.  See |auto-format|.

If the 'autoindent' option is on, Vim uses the indent of the first line for
the following lines.

Formatting does not change empty lines (but it does change lines with only
white space!).

The 'joinspaces' option is used when lines are joined together.

You can set the 'formatexpr' option to an expression or the 'formatprg' option
to the name of an external program for Vim to use for text formatting.  The
'textwidth' and other options have no effect on formatting by an external
program.

                                                        *right-justify*
There is no command in Vim to right justify text.  You can do it with
an external command, like "par" (e.g.: "!}par" to format until the end of the
paragraph) or set 'formatprg' to "par".

                                                        *format-comments*
Vim can format comments in a special way.  Vim recognizes a comment by a
specific string at the start of the line (ignoring white space).  Three types
of comments can be used:

- A comment string that repeats at the start of each line.  An example is the
  type of comment used in shell scripts, starting with "#".
- A comment string that occurs only in the first line, not in the following
  lines.  An example is this list with dashes.
- Three-piece comments that have a start string, an end string, and optional
  lines in between.  The strings for the start, middle and end are different.
  An example is the C-style comment:
        /*
         * this is a C comment
         */

The 'comments' option is a comma-separated list of parts.  Each part defines a
type of comment string.  A part consists of:
        {flags}:{string}

{string} is the literal text that must appear.

{flags}:
  n     Nested comment.  Nesting with mixed parts is allowed.  If 'comments'
        is "n:),n:>" a line starting with "> ) >" is a comment.

  b     Blank (<Space>, <Tab> or <EOL>) required after {string}.

  f     Only the first line has the comment string.  Do not repeat comment on
        the next line, but preserve indentation (e.g., a bullet-list).

  s     Start of three-piece comment

  m     Middle of a three-piece comment

  e     End of a three-piece comment

  l     Left adjust middle with start or end (default).  Only recognized when
        used together with 's' or 'e'.

  r     Right adjust middle with start or end.  Only recognized when used
        together with 's' or 'e'.

  O     Don't use this one for the "O" command.

  x     Allows three-piece comments to be ended by just typing the last
        character of the end-comment string as the first character on a new
        line, when the middle-comment string has already been inserted
        automatically.  See below for more details.

  {digits}
        When together with 's' or 'e': add extra indent for the middle part.
        This can be used to left-align the middle part with the start or end
        and then add an offset.

  -{digits}
        Like {digits} but reduce the indent.  This only works when there is
        some indent for the start or end part that can be removed.

When a string has none of the 'f', 's', 'm' or 'e' flags, Vim assumes the
comment string repeats at the start of each line.  The flags field may be
empty.

Any blank space in the text before and after the {string} is part of the
{string}, so do not include leading or trailing blanks unless the blanks are a
required part of the comment string.

When one comment leader is part of another, specify the part after the whole.
For example, to include both "-" and "->", use >
        :set comments=f:->,f:-

A three-piece comment must always be given as start,middle,end, with no other
parts in between.  An example of a three-piece comment is >
        sr:/*,mb:*,ex:*/
for C-comments.  To avoid recognizing "*ptr" as a comment, the middle string
includes the 'b' flag.  For three-piece comments, Vim checks the text after
the start and middle strings for the end string.  If Vim finds the end string,
the comment does not continue on the next line.  Three-piece comments must
have a middle string because otherwise Vim can't recognize the middle lines.

Notice the use of the "x" flag in the above three-piece comment definition.
When you hit Return in a C-comment, Vim will insert the middle comment leader
for the new line, e.g. " * ".  To close this comment you just have to type "/"
before typing anything else on the new line.  This will replace the
middle-comment leader with the end-comment leader, leaving just " */".  There
is no need to hit BackSpace first.

Examples: >
   "b:*"        Includes lines starting with "*", but not if the "*" is
                followed by a non-blank.  This avoids a pointer dereference
                like "*str" to be recognized as a comment.
   "n:>"        Includes a line starting with ">", ">>", ">>>", etc.
   "fb:-"       Format a list that starts with "- ".

By default, "b:#" is included.  This means that a line that starts with
"#include" is not recognized as a comment line.  But a line that starts with
"# define" is recognized.  This is a compromise.

Often the alignment can be changed from right alignment to a left alignment
with an additional space.  For example, for Javadoc comments, this can be
used (insert a backslash before the space when using ":set"): >
        s1:/*,mb:*,ex:*/
Note that an offset is included with start, so that the middle part is left
aligned with the start and then an offset of one character added.  This makes
it possible to left align the start and middle for this construction: >
        /**
         * comment
         */

{not available when compiled without the |+comments| feature}

                                                        *fo-table*
You can use the 'formatoptions' option  to influence how Vim formats text.
'formatoptions' is a string that can contain any of the letters below.  The
default setting is "tcq".  You can separate the option letters with commas for
readability.

letter   meaning when present in 'formatoptions'    ~

t       Auto-wrap text using textwidth
c       Auto-wrap comments using textwidth, inserting the current comment
        leader automatically.
r       Automatically insert the current comment leader after hitting
        <Enter> in Insert mode.
o       Automatically insert the current comment leader after hitting 'o' or
        'O' in Normal mode.
q       Allow formatting of comments with "gq".
        Note that formatting will not change blank lines or lines containing
        only the comment leader.  A new paragraph starts after such a line,
        or when the comment leader changes.
w       Trailing white space indicates a paragraph continues in the next line.
        A line that ends in a non-white character ends a paragraph.
a       Automatic formatting of paragraphs.  Every time text is inserted or
        deleted the paragraph will be reformatted.  See |auto-format|.
        When the 'c' flag is present this only happens for recognized
        comments.
n       When formatting text, recognize numbered lists.  This actually uses
        the 'formatlistpat' option, thus any kind of list can be used.  The
        indent of the text after the number is used for the next line.  The
        default is to find a number, optionally be followed by '.', ':', ')',
        ']' or '}'.  Note that 'autoindent' must be set too.  Doesn't work
        well together with "2".
        Example: >
                1. the first item
                   wraps
                2. the second item
2       When formatting text, use the indent of the second line of a paragraph
        for the rest of the paragraph, instead of the indent of the first
        line.  This supports paragraphs in which the first line has a
        different indent than the rest.  Note that 'autoindent' must be set
        too.  Example: >
                        first line of a paragraph
                second line of the same paragraph
                third line.
v       Vi-compatible auto-wrapping in insert mode: Only break a line at a
        blank that you have entered during the current insert command.  (Note:
        this is not 100% Vi compatible.  Vi has some "unexpected features" or
        bugs in this area.  It uses the screen column instead of the line
        column.)
b       Like 'v', but only auto-wrap if you enter a blank at or before
        the wrap margin.  If the line was longer than 'textwidth' when you
        started the insert, or you do not enter a blank in the insert before
        reaching 'textwidth', Vim does not perform auto-wrapping.
l       Long lines are not broken in insert mode: When a line was longer than
        'textwidth' when the insert command started, Vim does not
        automatically format it.
m       Also break at a multi-byte character above 255.  This is useful for
        Asian text where every character is a word on its own.
M       When joining lines, don't insert a space before or after a multi-byte
        character.  Overrules the 'B' flag.
B       When joining lines, don't insert a space between two multi-byte
        characters.  Overruled by the 'M' flag.
1       Don't break a line after a one-letter word.  It's broken before it
        instead (if possible).


With 't' and 'c' you can specify when Vim performs auto-wrapping:
value   action  ~
""      no automatic formatting (you can use "gq" for manual formatting)
"t"     automatic formatting of text, but not comments
"c"     automatic formatting for comments, but not text (good for C code)
"tc"    automatic formatting for text and comments

Note that when 'textwidth' is 0, Vim does no automatic formatting anyway (but
does insert comment leaders according to the 'comments' option).  An exception
is when the 'a' flag is present. |auto-format|

Note that when 'paste' is on, Vim does no formatting at all.

Note that 'textwidth' can be non-zero even if Vim never performs auto-wrapping;
'textwidth' is still useful for formatting with "gq".

If the 'comments' option includes "/*", "*" and/or "*/", then Vim has some
built in stuff to treat these types of comments a bit more cleverly.
Opening a new line before or after "/*" or "*/" (with 'r' or 'o' present in
'formatoptions') gives the correct start of the line automatically.  The same
happens with formatting and auto-wrapping.  Opening a line after a line
starting with "/*" or "*" and containing "*/", will cause no comment leader to
be inserted, and the indent of the new line is taken from the line containing
the start of the comment.
E.g.:
    /* ~
     * Your typical comment. ~
     */ ~
    The indent on this line is the same as the start of the above
    comment.

All of this should be really cool, especially in conjunction with the new
:autocmd command to prepare different settings for different types of file.

Some examples:
  for C code (only format comments): >
        :set fo=croq
< for Mail/news (format all, don't start comment with "o" command): >
        :set fo=tcrq
<

Automatic formatting                                    *auto-format*

When the 'a' flag is present in 'formatoptions' text is formatted
automatically when inserting text or deleting text.  This works nice for
editing text paragraphs.  A few hints on how to use this:

- You need to properly define paragraphs.  The simplest is paragraphs that are
  separated by a blank line.  When there is no separating blank line, consider
  using the 'w' flag and adding a space at the end of each line in the
  paragraphs except the last one.

- You can set the 'formatoptions' based on the type of file |filetype| or
  specifically for one file with a |modeline|.

- Set 'formatoptions' to "aw2tq" to make text with indents like this:

            bla bla foobar bla
        bla foobar bla foobar bla
            bla bla foobar bla
        bla foobar bla bla foobar

- Add the 'c' flag to only auto-format comments.  Useful in source code.

- Set 'textwidth' to the desired width.  If it is zero then 79 is used, or the
  width of the screen if this is smaller.

And a few warnings:

- When part of the text is not properly separated in paragraphs, making
  changes in this text will cause it to be formatted anyway.  Consider doing >

        :set fo-=a

- When using the 'w' flag (trailing space means paragraph continues) and
  deleting the last line of a paragraph with |dd|, the paragraph will be
  joined with the next one.

- Changed text is saved for undo.  Formatting is also a change.  Thus each
  format action saves text for undo.  This may consume quite a lot of memory.

- Formatting a long paragraph and/or with complicated indenting may be slow.

==============================================================================
7. Sorting text                                         *sorting*

Vim has a sorting function and a sorting command.  The sorting function can be
found here: |sort()|.

                                                        *:sor* *:sort*
:[range]sor[t][!] [i][u][r][n][x][o] [/{pattern}/]
                        Sort lines in [range].  When no range is given all
                        lines are sorted.

                        With [!] the order is reversed.

                        With [i] case is ignored.

                        With [n] sorting is done on the first decimal number
                        in the line (after or inside a {pattern} match).

                        With [x] sorting is done on the first hexadecimal
                        number in the line (after or inside a {pattern}
                        match).  A leading "0x" or "0X" is ignored.

                        With [o] sorting is done on the first octal number in
                        the line (after or inside a {pattern} match).

                        With [u] only keep the first of a sequence of
                        identical lines (ignoring case when [i] is used).
                        Without this flag, a sequence of identical lines
                        will be kept in their original order.
                        Note that leading and trailing white space may cause
                        lines to be different.

                        When /{pattern}/ is specified and there is no [r] flag
                        the text matched with {pattern} is skipped, so that
                        you sort on what comes after the match.
                        Instead of the slash any non-letter can be used.
                        For example, to sort on the second comma-separated
                        field: >
                                :sort /[^,]*,/
<                       To sort on the text at virtual column 10 (thus
                        ignoring the difference between tabs and spaces): >
                                :sort /.*\%10v/
<                       To sort on the first number in the line, no matter
                        what is in front of it: >
                                :sort /.*\ze\d/

<                       With [r] sorting is done on the matching {pattern}
                        instead of skipping past it as described above.
                        For example, to sort on only the first three letters
                        of each line: >
                                :sort /\a\a\a/ r

<                       If a {pattern} is used, any lines which don't have a
                        match for {pattern} are kept in their current order,
                        but separate from the lines which do match {pattern}.
                        If you sorted in reverse, they will be in reverse
                        order after the sorted lines, otherwise they will be
                        in their original order, right before the sorted
                        lines.

                        If {pattern} is empty (e.g. // is specified), the
                        last search pattern is used.  This allows trying out
                        a pattern first.

Note that using ":sort" with ":global" doesn't sort the matching lines, it's
quite useless.

The details about sorting depend on the library function used.  There is no
guarantee that sorting is "stable" or obeys the current locale.  You will have
to try it out.

The sorting can be interrupted, but if you interrupt it too late in the
process you may end up with duplicated lines.  This also depends on the system
library function used.

2.2 编辑模式下帮助文档

                        Alphabetic characters and characters in 'isfname'
                        are used to decide which characters are included in
                        the file name.  Note: the 'path' option is not used
                        here (yet).
        CTRL-F  or
        CTRL-N          Search forwards for next matching file name.  This
                        file name replaces the previous matching file name.

        CTRL-P          Search backward for previous matching file name.
                        This file name replaces the previous matching file
                        name.


Completing definitions or macros                        *compl-define*

The 'define' option is used to specify a line that contains a definition.
The 'include' option is used to specify a line that contains an include file
name.  The 'path' option is used to search for include files.

                                                        *i_CTRL-X_CTRL-D*
CTRL-X CTRL-D           Search in the current and included files for the
                        first definition (or macro) name that starts with
                        the same characters as before the cursor.  The found
                        definition name is inserted in front of the cursor.
        CTRL-D  or
        CTRL-N          Search forwards for next matching macro name.  This
                        macro name replaces the previous matching macro
                        name.

        CTRL-P          Search backward for previous matching macro name.
                        This macro name replaces the previous matching macro
                        name.

        CTRL-X CTRL-D   Further use of CTRL-X CTRL-D will copy the words
                        following the previous expansion in other contexts
                        unless a double CTRL-X is used.


Completing Vim commands                                 *compl-vim*

Completion is context-sensitive.  It works like on the Command-line.  It
completes an Ex command as well as its arguments.  This is useful when writing
a Vim script.

                                                        *i_CTRL-X_CTRL-V*
CTRL-X CTRL-V           Guess what kind of item is in front of the cursor and
                        find the first match for it.
                        Note: When CTRL-V is mapped you can often use CTRL-Q
                        instead |i_CTRL-Q|.
        CTRL-V  or
        CTRL-N          Search forwards for next match.  This match replaces
                        the previous one.

        CTRL-P          Search backward for previous match.  This match
                        replaces the previous one.

        CTRL-X CTRL-V   Further use of CTRL-X CTRL-V will do the same as
                        CTRL-V.  This allows mapping a key to do Vim command
                        completion, for example: >
                                :imap <Tab> <C-X><C-V>

User defined completion                                 *compl-function*

Completion is done by a function that can be defined by the user with the
'completefunc' option.  See below for how the function is called and an
example |complete-functions|.

                                                        *i_CTRL-X_CTRL-U*
CTRL-X CTRL-U           Guess what kind of item is in front of the cursor and
                        find the first match for it.
        CTRL-U  or
        CTRL-N          Use the next match.  This match replaces the previous
                        one.

        CTRL-P          Use the previous match.  This match replaces the
                        previous one.


Omni completion                                         *compl-omni*

Completion is done by a function that can be defined by the user with the
'omnifunc' option.  This is to be used for filetype-specific completion.

See below for how the function is called and an example |complete-functions|.
For remarks about specific filetypes see |compl-omni-filetypes|.
More completion scripts will appear, check www.vim.org.  Currently there is a
first version for C++.

                                                        *i_CTRL-X_CTRL-O*
CTRL-X CTRL-O           Guess what kind of item is in front of the cursor and
                        find the first match for it.
        CTRL-O  or
        CTRL-N          Use the next match.  This match replaces the previous
                        one.

        CTRL-P          Use the previous match.  This match replaces the
                        previous one.


Spelling suggestions                                    *compl-spelling*

A word before or at the cursor is located and correctly spelled words are
suggested to replace it.  If there is a badly spelled word in the line, before
or under the cursor, the cursor is moved to after it.  Otherwise the word just
before the cursor is used for suggestions, even though it isn't badly spelled.

NOTE: CTRL-S suspends display in many Unix terminals.  Use 's' instead.  Type
CTRL-Q to resume displaying.

                                                *i_CTRL-X_CTRL-S* *i_CTRL-X_s*
CTRL-X CTRL-S   or
CTRL-X s                Locate the word in front of the cursor and find the
                        first spell suggestion for it.
        CTRL-S  or
        CTRL-N          Use the next suggestion.  This replaces the previous
                        one.  Note that you can't use 's' here.

        CTRL-P          Use the previous suggestion.  This replaces the
                        previous one.


Completing keywords from different sources              *compl-generic*

                                                        *i_CTRL-N*
CTRL-N                  Find next match for words that start with the
                        keyword in front of the cursor, looking in places
                        specified with the 'complete' option.  The found
                        keyword is inserted in front of the cursor.

                                                        *i_CTRL-P*
CTRL-P                  Find previous match for words that start with the
                        keyword in front of the cursor, looking in places
                        specified with the 'complete' option.  The found
                        keyword is inserted in front of the cursor.

        CTRL-N          Search forward for next matching keyword.  This
                        keyword replaces the previous matching keyword.

        CTRL-P          Search backwards for next matching keyword.  This
                        keyword replaces the previous matching keyword.

        CTRL-X CTRL-N or
        CTRL-X CTRL-P   Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will
                        copy the words following the previous expansion in
                        other contexts unless a double CTRL-X is used.


FUNCTIONS FOR FINDING COMPLETIONS                       *complete-functions*

This applies to 'completefunc' and 'omnifunc'.

The function is called in two different ways:
- First the function is called to find the start of the text to be completed.
- Later the function is called to actually find the matches.

On the first invocation the arguments are:
   a:findstart  1
   a:base       empty

The function must return the column where the completion starts.  It must be a
number between zero and the cursor column "col('.')".  This involves looking
at the characters just before the cursor and including those characters that
could be part of the completed item.  The text between this column and the
cursor column will be replaced with the matches.  Return -1 if no completion
can be done.

On the second invocation the arguments are:
   a:findstart  0
   a:base       the text with which matches should match; the text that was
                located in the first call (can be empty)

The function must return a List with the matching words.  These matches
usually include the "a:base" text.  When there are no matches return an empty
List.
                                                *complete-items*
Each list item can either be a string or a Dictionary.  When it is a string it
is used as the completion.  When it is a Dictionary it can contain these
items:
        word            the text that will be inserted, mandatory
        abbr            abbreviation of "word"; when not empty it is used in
                        the menu instead of "word"
        menu            extra text for the popup menu, displayed after "word"
                        or "abbr"
        info            more information about the item, can be displayed in a
                        preview window
        kind            single letter indicating the type of completion
        icase           when non-zero case is to be ignored when comparing
                        items to be equal; when omitted zero is used, thus
                        items that only differ in case are added
        dup             when non-zero this match will be added even when an
                        item with the same word is already present.

All of these except 'icase' must be a string.  If an item does not meet these
requirements then an error message is given and further items in the list are
not used.  You can mix string and Dictionary items in the returned list.

The "menu" item is used in the popup menu and may be truncated, thus it should
be relatively short.  The "info" item can be longer, it will  be displayed in
the preview window when "preview" appears in 'completeopt'.  The "info" item
will also remain displayed after the popup menu has been removed.  This is
useful for function arguments.  Use a single space for "info" to remove
existing text in the preview window.

The "kind" item uses a single letter to indicate the kind of completion.  This
may be used to show the completion differently (different color or icon).
Currently these types can be used:
        v       variable
        f       function or method
        m       member of a struct or class
        t       typedef
        d       #define or macro

When searching for matches takes some time call |complete_add()| to add each
match to the total list.  These matches should then not appear in the returned
list!  Call |complete_check()| now and then to allow the user to press a key
while still searching for matches.  Stop searching when it returns non-zero.

The function is allowed to move the cursor, it is restored afterwards.  This
option cannot be set from a |modeline| or in the |sandbox|, for security
reasons.

An example that completes the names of the months: >
        fun! CompleteMonths(findstart, base)
          if a:findstart
            " locate the start of the word
            let line = getline('.')
            let start = col('.') - 1
            while start > 0 && line[start - 1] =~ '\a'
              let start -= 1
            endwhile
            return start
          else
            " find months matching with "a:base"
            let res = []
            for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")
              if m =~ '^' . a:base
                call add(res, m)
              endif
            endfor
            return res
          endif
        endfun
        set completefunc=CompleteMonths
<
The same, but now pretending searching for matches is slow: >
        fun! CompleteMonths(findstart, base)
          if a:findstart
            " locate the start of the word
            let line = getline('.')
            let start = col('.') - 1
            while start > 0 && line[start - 1] =~ '\a'
              let start -= 1
            endwhile
            return start
          else
            " find months matching with "a:base"
            for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")
              if m =~ '^' . a:base
                call complete_add(m)
              endif
              sleep 300m        " simulate searching for next match
              if complete_check()
                break
              endif
            endfor
            return []
          endif
        endfun
        set completefunc=CompleteMonths
<

INSERT COMPLETION POPUP MENU                            *ins-completion-menu*
                                                        *popupmenu-completion*
Vim can display the matches in a simplistic popup menu.

The menu is used when:
- The 'completeopt' option contains "menu" or "menuone".
- The terminal supports at least 8 colors.
- There are at least two matches.  One if "menuone" is used.

The 'pumheight' option can be used to set a maximum height.  The default is to
use all space available.

There are three states:
1. A complete match has been inserted, e.g., after using CTRL-N or CTRL-P.
2. A cursor key has been used to select another match.  The match was not
   inserted then, only the entry in the popup menu is highlighted.
3. Only part of a match has been inserted and characters were typed or the
   backspace key was used.  The list of matches was then adjusted for what is
   in front of the cursor.

You normally start in the first state, with the first match being inserted.
When "longest" is in 'completeopt' and there is more than one match you start
in the third state.

If you select another match, e.g., with CTRL-N or CTRL-P, you go to the first
state.  This doesn't change the list of matches.

When you are back at the original text then you are in the third state.  To
get there right away you can use a mapping that uses CTRL-P right after
starting the completion: >
        :imap <F7> <C-N><C-P>
<
                                                *popupmenu-keys*
In the first state these keys have a special meaning:
<BS> and CTRL-H   Delete one character, find the matches for the word before
                  the cursor.  This reduces the list of matches, often to one
                  entry, and switches to the second state.
Any non-special character:
                  Stop completion without changing the match and insert the
                  typed character.

In the second and third state these keys have a special meaning:
<BS> and CTRL-H   Delete one character, find the matches for the shorter word
                  before the cursor.  This may find more matches.
CTRL-L            Add one character from the current match, may reduce the
                  number of matches.
any printable, non-white character:
                  Add this character and reduce the number of matches.

In all three states these can be used:
CTRL-Y            Yes: Accept the currently selected match and stop completion.
CTRL-E            End completion, go back to what was there before selecting a
                  match (what was typed or longest common string).
<PageUp>          Select a match several entries back, but don't insert it.
<PageDown>        Select a match several entries further, but don't insert it.
<Up>              Select the previous match, as if CTRL-P was used, but don't
                  insert it.
<Down>            Select the next match, as if CTRL-N was used, but don't
                  insert it.
<Space> or <Tab>  Stop completion without changing the match and insert the
                  typed character.

The behavior of the <Enter> key depends on the state you are in:
first state:      Use the text as it is and insert a line break.
second state:     Insert the currently selected match.
third state:      Use the text as it is and insert a line break.

In other words: If you used the cursor keys to select another entry in the
list of matches then the <Enter> key inserts that match.  If you typed
something else then <Enter> inserts a line break.


The colors of the menu can be changed with these highlight groups:
Pmenu           normal item  |hl-Pmenu|
PmenuSel        selected item  |hl-PmenuSel|
PmenuSbar       scrollbar  |hl-PmenuSbar|
PmenuThumb      thumb of the scrollbar  |hl-PmenuThumb|

There are no special mappings for when the popup menu is visible.  However,
you can use an Insert mode mapping that checks the |pumvisible()| function to
do something different.  Example: >
        :inoremap <Down> <C-R>=pumvisible() ? "\<lt>C-N>" : "\<lt>Down>"<CR>

You can use of <expr> in mapping to have the popup menu used when typing a
character and some condition is met.  For example, for typing a dot: >
        inoremap <expr> . MayComplete()
        func MayComplete()
            if (can complete)
              return ".\<C-X>\<C-O>"
            endif
            return '.'
        endfunc

See |:map-<expr>| for more info.


FILETYPE-SPECIFIC REMARKS FOR OMNI COMPLETION       *compl-omni-filetypes*

The file used for {filetype} should be autoload/{filetype}complete.vim
in 'runtimepath'.  Thus for "java" it is autoload/javacomplete.vim.


C                                                       *ft-c-omni*

Completion of C code requires a tags file.  You should use Exuberant ctags,
because it adds extra information that is needed for completion.  You can find
it here: http://ctags.sourceforge.net/  Version 5.6 or later is recommended.

For version 5.5.4 you should add a patch that adds the "typename:" field:
        ftp://ftp.vim.org/pub/vim/unstable/patches/ctags-5.5.4.patch
A compiled .exe for MS-Windows can be found at:
        http://georgevreilly.com/vim/ctags.html

If you want to complete system functions you can do something like this.  Use
ctags to generate a tags file for all the system header files: >
        % ctags -R -f ~/.vim/systags /usr/include /usr/local/include
In your vimrc file add this tags file to the 'tags' option: >
        set tags+=~/.vim/systags

When using CTRL-X CTRL-O after a name without any "." or "->" it is completed
from the tags file directly.  This works for any identifier, also function
names.  If you want to complete a local variable name, which does not appear
in the tags file, use CTRL-P instead.

When using CTRL-X CTRL-O after something that has "." or "->" Vim will attempt
to recognize the type of the variable and figure out what members it has.
This means only members valid for the variable will be listed.

When a member name already was complete, CTRL-X CTRL-O will add a "." or
"->" for composite types.

Vim doesn't include a C compiler, only the most obviously formatted
declarations are recognized.  Preprocessor stuff may cause confusion.
When the same structure name appears in multiple places all possible members
are included.


CSS                                                     *ft-css-omni*

Complete properties and their appropriate values according to CSS 2.1
specification.


HTML                                                    *ft-html-omni*
XHTML                                                   *ft-xhtml-omni*

CTRL-X CTRL-O provides completion of various elements of (X)HTML files.  It is
designed to support writing of XHTML 1.0 Strict files but will also works for
other versions of HTML. Features:

- after "<" complete tag name depending on context (no div suggestion inside
  of an a tag); '/>' indicates empty tags
- inside of tag complete proper attributes (no width attribute for an a tag);
  show also type of attribute; '*' indicates required attributes
- when attribute has limited number of possible values help to complete them
- complete names of entities
- complete values of "class" and "id" attributes with data obtained from
  <style> tag and included CSS files
- when completing value of "style" attribute or working inside of "style" tag
  switch to |ft-css-omni| completion
- when completing values of events attributes or working inside of "script"
  tag switch to |ft-javascript-omni| completion
- when used after "</" CTRL-X CTRL-O will close the last opened tag

Note: When used first time completion menu will be shown with little delay
- this is time needed for loading of data file.
Note: Completion may fail in badly formatted documents. In such case try to
run |:make| command to detect formatting problems.


HTML flavor                                             *html-flavor*

The default HTML completion depends on the filetype.  For HTML files it is
HTML 4.01 Transitional ('filetype' is "html"), for XHTML it is XHTML 1.0
Strict ('filetype' is "xhtml").

When doing completion outside of any other tag you will have possibility to
choose DOCTYPE and the appropriate data file will be loaded and used for all
next completions.

More about format of data file in |xml-omni-datafile|. Some of the data files
may be found on the Vim website (|www|).

Note that b:html_omni_flavor may point to a file with any XML data.  This
makes possible to mix PHP (|ft-php-omni|) completion with any XML dialect
(assuming you have data file for it).  Without setting that variable XHTML 1.0
Strict will be used.


JAVASCRIPT                                             *ft-javascript-omni*

Completion of most elements of JavaScript language and DOM elements.

Complete:

- variables
- function name; show function arguments
- function arguments
- properties of variables trying to detect type of variable
- complete DOM objects and properties depending on context
- keywords of language

Completion works in separate JavaScript files (&ft==javascript), inside of
<script> tag of (X)HTML and in values of event attributes (including scanning
of external files.

DOM compatibility

At the moment (beginning of 2006) there are two main browsers - MS Internet
Explorer and Mozilla Firefox. These two applications are covering over 90% of
market. Theoretically standards are created by W3C organisation
(http://www.w3c.org) but they are not always followed/implemented.

                IE      FF      W3C  Omni completion ~
                +/-     +/-     +    +               ~
                +       +       -    +               ~
                +       -       -    -               ~
                -       +       -    -               ~

Regardless from state of implementation in browsers but if element is defined
in standards, completion plugin will place element in suggestion list. When
both major engines implemented element, even if this is not in standards it
will be suggested. All other elements are not placed in suggestion list.


PHP                                                     *ft-php-omni*

Completion of PHP code requires a tags file for completion of data from
external files and for class aware completion. You should use Exuberant ctags
version 5.5.4 or newer. You can find it here: http://ctags.sourceforge.net/

Script completes:

- after $ variables name
  - if variable was declared as object add "->", if tags file is available show
    name of class
  - after "->" complete only function and variable names specific for given
    class. To find class location and contents tags file is required. Because
    PHP isn't strongly typed language user can use @var tag to declare class: >

        /* @var $myVar myClass */
        $myVar->
<
    Still, to find myClass contents tags file is required.

- function names with additional info:
  - in case of built-in functions list of possible arguments and after | type
    data returned by function
  - in case of user function arguments and name of file were function was
    defined (if it is not current file)

- constants names
- class names after "new" declaration


Note: when doing completion first time Vim will load all necessary data into
memory. It may take several seconds. After next use of completion delay
should not be noticeable.

Script detects if cursor is inside <?php ?> tags. If it is outside it will
automatically switch to HTML/CSS/JavaScript completion. Note: contrary to
original HTML files completion of tags (and only tags) isn't context aware.


RUBY                                                    *ft-ruby-omni*

Completion of Ruby code requires that vim be built with |+ruby|.

Ruby completion will parse your buffer on demand in order to provide a list of
completions.  These completions will be drawn from modules loaded by 'require'
and modules defined in the current buffer.

The completions provided by CTRL-X CTRL-O are sensitive to the context:

          CONTEXT                          COMPLETIONS PROVIDED ~

 1. Not inside a class definition    Classes, constants and globals

 2. Inside a class definition        Methods or constants defined in the class

 3. After '.', '::' or ':'           Methods applicable to the object being
                                       dereferenced

 4. After ':' or ':foo'              Symbol name (beginning with 'foo')

Notes:
 - Vim will load/evaluate code in order to provide completions.  This may
   cause some code execution, which may be a concern. This is no longer
   enabled by default, to enable this feature add >
     let g:rubycomplete_buffer_loading = 1
<- In context 1 above, Vim can parse the entire buffer to add a list of
   classes to the completion results. This feature is turned off by default,
   to enable it add >
     let g:rubycomplete_classes_in_global = 1
<  to your vimrc
 - In context 2 above, anonymous classes are not supported.
 - In context 3 above, Vim will attempt to determine the methods supported by
   the object.
 - Vim can detect and load the Rails environment for files within a rails
   project. The feature is disabled by default, to enable it add >
     let g:rubycomplete_rails = 1
<  to your vimrc


SYNTAX                                                  *ft-syntax-omni*

Vim has the ability to color syntax highlight nearly 500 languages.  Part of
this highlighting includes knowing what keywords are part of a language.  Many
filetypes already have custom completion scripts written for them, the
syntaxcomplete plugin provides basic completion for all other filetypes.  It
does this by populating the omni completion list with the text Vim already
knows how to color highlight.  It can be used for any filetype and provides a
minimal language-sensitive completion.

To enable syntax code completion you can run: >
        setlocal omnifunc=syntaxcomplete#Complete

You can automate this by placing the following in your vimrc (after any
":filetype" command): >
    if has("autocmd") && exists("+omnifunc")
        autocmd Filetype *
                    \   if &omnifunc == "" |
                    \           setlocal omnifunc=syntaxcomplete#Complete |
                    \   endif
    endif

The above will set completion to this script only if a specific plugin does
not already exist for that filetype.

Each filetype can have a wide range of syntax items.  The plugin allows you to
customize which syntax groups to include or exclude from the list.  Let's have
a look at the PHP filetype to see how this works.

If you edit a file called, index.php, run the following command: >
        :syntax list

First thing you will notice is there are many different syntax groups.  The
PHP language can include elements from different languages like HTML,
JavaScript and many more.  The syntax plugin will only include syntax groups
that begin with the filetype, "php", in this case.  For example these syntax
groups are included by default with the PHP: phpEnvVar, phpIntVar,
phpFunctions.

The PHP language has an enormous number of items which it knows how to syntax
highlight.  This means these items will be available within the omni
completion list.  Some people may find this list unwieldy or are only
interested in certain items.

There are two ways to prune this list (if necessary).  If you find certain
syntax groups you do not wish displayed you can add the following to your
vimrc: >
        let g:omni_syntax_group_exclude_php = 'phpCoreConstant,phpConstant'

Add as many syntax groups to this list by comma separating them.  The basic
form of this variable is: >
        let g:omni_syntax_group_exclude_{filetype} = 'comma,separated,list'

For completeness the opposite is also true.  Creating this variable in your
vimrc will only include the items in the phpFunctions and phpMethods syntax
groups: >
        let g:omni_syntax_group_include_php = 'phpFunctions,phpMethods'

You can create as many of these variables as you need, varying only the
filetype at the end of the variable name.

The plugin uses the isKeyword option to determine where word boundaries are
for the syntax items.  For example, in the Scheme language completion should
include the "-", call-with-output-file.  Depending on your filetype, this may
not provide the words you are expecting.  Setting the
g:omni_syntax_use_iskeyword option to 0 will force the syntax plugin to break
on word characters.   This can be controlled adding the following to your
vimrc: >
    let g:omni_syntax_use_iskeyword = 0


SQL                                                     *ft-sql-omni*

Completion for the SQL language includes statements, functions, keywords.
It will also dynamically complete tables, procedures, views and column lists
with data pulled directly from within a database.  For detailed instructions
and a tutorial see |omni-sql-completion|.

The SQL completion plugin can be used in conjunction with other completion
plugins.  For example, the PHP filetype has it's own completion plugin.
Since PHP is often used to generate dynamic website by accessing a database,
the SQL completion plugin can also be enabled.  This allows you to complete
PHP code and SQL code at the same time.


XML                                                     *ft-xml-omni*

Vim 7 provides a mechanism for context aware completion of XML files.  It
depends on a special |xml-omni-datafile| and two commands: |:XMLns| and
|:XMLent|.  Features are:

- after "<" complete the tag name, depending on context
- inside of a tag complete proper attributes
- when an attribute has a limited number of possible values help to complete
  them
- complete names of entities (defined in |xml-omni-datafile| and in the
  current file with "<!ENTITY" declarations)
- when used after "</" CTRL-X CTRL-O will close the last opened tag

Format of XML data file                                 *xml-omni-datafile*

XML data files are stored in the "autoload/xml" directory in 'runtimepath'.
Vim distribution provides examples of data files in the
"$VIMRUNTIME/autoload/xml" directory.  They have a meaningful name which will
be used in commands.  It should be a unique name which will not create
conflicts.  For example, the name xhtml10s.vim means it is the data file for
XHTML 1.0 Strict.

Each file contains a variable with a name like g:xmldata_xhtml10s . It is
a compound from two parts:

1. "g:xmldata_"  general prefix, constant for all data files
2. "xhtml10s"    the name of the file and the name of the described XML
                 dialect; it will be used as an argument for the |:XMLns|
                 command

Part two must be exactly the same as name of file.

The variable is a |Dictionary|.  Keys are tag names and each value is a two
element |List|.  The first element of the List is also a List with the names
of possible children.  The second element is a |Dictionary| with the names of
attributes as keys and the possible values of attributes as values.  Example: >

    let g:xmldata_crippled = {
    \ "vimxmlentities": ["amp", "lt", "gt", "apos", "quot"],
    \ 'vimxmlroot': ['tag1'],
    \ 'tag1':
    \ [ ['childoftag1a', 'childoftag1b'], {'attroftag1a': [],
    \ 'attroftag1b': ['valueofattr1', 'valueofattr2']}],
    \ 'childoftag1a':
    \ [ [], {'attrofchild': ['attrofchild']}],
    \ 'childoftag1b':
    \ [ ['childoftag1a'], {'attrofchild': []}],
    \ "vimxmltaginfo": {
    \ 'tag1': ['Menu info', 'Long information visible in preview window']},
    \ 'vimxmlattrinfo': {
    \ 'attrofchild': ['Menu info', 'Long information visible in preview window']}}

This example would be put in the "autoload/xml/crippled.vim" file and could
help to write this file: >

    <tag1 attroftag1b="valueofattr1">
        <childoftag1a attrofchild>
                &amp; &lt;
        </childoftag1a>
        <childoftag1b attrofchild="5">
            <childoftag1a>
                &gt; &apos; &quot;
            </childoftag1a>
        </childoftag1b>
    </tag1>

In the example four special elements are visible:

1. "vimxmlentities" - a special key with List containing entities of this XML
   dialect.
2. If the list containing possible values of attributes has one element and
   this element is equal to the name of the attribute this attribute will be
   treated as boolean and inserted as 'attrname' and not as 'attrname="'
3. "vimxmltaginfo" - a special key with a Dictionary containing tag
   names as keys and two element List as values, for additional menu info and
   the long description.
4. "vimxmlattrinfo" - special key with Dictionary containing attribute names
   as keys and two element List as values, for additional menu info and long
   description.

Note: Tag names in the data file MUST not contain a namespace description.
Check xsl.vim for an example.
Note: All data and functions are publicly available as global
variables/functions and can be used for personal editing functions.


DTD -> Vim                                                      *dtd2vim*

On |www| is the script |dtd2vim| which parses DTD and creates an XML data file
for Vim XML omni completion.

    dtd2vim: http://www.vim.org/scripts/script.php?script_id=1462

Check the beginning of that file for usage details.
The script requires perl and:

    perlSGML: http://savannah.nongnu.org/projects/perlsgml


Commands

:XMLns {name} [{namespace}]                                     *:XMLns*

Vim has to know which data file should be used and with which namespace.  For
loading of the data file and connecting data with the proper namespace use
|:XMLns| command.  The first (obligatory) argument is the name of the data
(xhtml10s, xsl).  The second argument is the code of namespace (h, xsl).  When
used without a second argument the dialect will be used as default - without
namespace declaration.  For example to use XML completion in .xsl files: >

        :XMLns xhtml10s
        :XMLns xsl xsl


:XMLent {name}                                                  *:XMLent*

By default entities will be completed from the data file of the default
namespace.  The XMLent command should be used in case when there is no default
namespace: >

        :XMLent xhtml10s

Usage

While used in this situation (after declarations from previous part, | is
cursor position): >

        <|

Will complete to an appropriate XHTML tag, and in this situation: >

        <xsl:|

Will complete to an appropriate XSL tag.


The script xmlcomplete.vim, provided through the |autoload| mechanism,
has the xmlcomplete#GetLastOpenTag() function which can be used in XML files
to get the name of the last open tag (b:unaryTagsStack has to be defined): >

        :echo xmlcomplete#GetLastOpenTag("b:unaryTagsStack")



==============================================================================
8. Insert mode commands                                 *inserting*

The following commands can be used to insert new text into the buffer.  They
can all be undone and repeated with the "." command.

                                                        *a*
a                       Append text after the cursor [count] times.  If the
                        cursor is in the first column of an empty line Insert
                        starts there.  But not when 'virtualedit' is set!

                                                        *A*
A                       Append text at the end of the line [count] times.

<insert>        or                              *i* *insert* *<Insert>*
i                       Insert text before the cursor [count] times.
                        When using CTRL-O in Insert mode |i_CTRL-O| the count
                        is not supported.

                                                        *I*
I                       Insert text before the first non-blank in the line
                        [count] times.
                        When the 'H' flag is present in 'cpoptions' and the
                        line only contains blanks, insert start just before
                        the last blank.

                                                        *gI*
gI                      Insert text in column 1 [count] times.  {not in Vi}

                                                        *gi*
gi                      Insert text in the same position as where Insert mode
                        was stopped last time in the current buffer.
                        This uses the |'^| mark.  It's different from "`^i"
                        when the mark is past the end of the line.
                        The position is corrected for inserted/deleted lines,
                        but NOT for inserted/deleted characters.
                        When the |:keepjumps| command modifier is used the |'^|
                        mark won't be changed.
                        {not in Vi}

                                                        *o*
o                       Begin a new line below the cursor and insert text,
                        repeat [count] times.  {Vi: blank [count] screen
                        lines}
                        When the '#' flag is in 'cpoptions' the count is
                        ignored.

                                                        *O*
O                       Begin a new line above the cursor and insert text,
                        repeat [count] times.  {Vi: blank [count] screen
                        lines}
                        When the '#' flag is in 'cpoptions' the count is
                        ignored.

These commands are used to start inserting text.  You can end insert mode with
<Esc>.  See |mode-ins-repl| for the other special characters in Insert mode.
The effect of [count] takes place after Insert mode is exited.

When 'autoindent' is on, the indent for a new line is obtained from the
previous line.  When 'smartindent' or 'cindent' is on, the indent for a line
is automatically adjusted for C programs.

'textwidth' can be set to the maximum width for a line.  When a line becomes
too long when appending characters a line break is automatically inserted.


==============================================================================
9. Ex insert commands                                   *inserting-ex*

                                                        *:a* *:append*
:{range}a[ppend][!]     Insert several lines of text below the specified
                        line.  If the {range} is missing, the text will be
                        inserted after the current line.
                        Adding [!] toggles 'autoindent' for the time this
                        command is executed.

                                                        *:i* *:in* *:insert*
:{range}i[nsert][!]     Insert several lines of text above the specified
                        line.  If the {range} is missing, the text will be
                        inserted before the current line.
                        Adding [!] toggles 'autoindent' for the time this
                        command is executed.

These two commands will keep on asking for lines, until you type a line
containing only a ".".  Watch out for lines starting with a backslash, see
|line-continuation|.
When these commands are used with |:global| or |:vglobal| then the lines are
obtained from the text following the command.  Separate lines with a NL
escaped with a backslash: >
        :global/abc/insert\
        one line\
        another line
The final "." is not needed then.
NOTE: ":append" and ":insert" don't work properly in between ":if" and
":endif", ":for" and ":endfor", ":while" and ":endwhile".

                                                        *:start* *:startinsert*
:star[tinsert][!]       Start Insert mode just after executing this command.
                        Works like typing "i" in Normal mode.  When the ! is
                        included it works like "A", append to the line.
                        Otherwise insertion starts at the cursor position.
                        Note that when using this command in a function or
                        script, the insertion only starts after the function
                        or script is finished.
                        This command does not work from |:normal|.
                        {not in Vi}
                        {not available when compiled without the +ex_extra
                        feature}

                                                        *:stopi* *:stopinsert*
:stopi[nsert]           Stop Insert mode as soon as possible.  Works like
                        typing <Esc> in Insert mode.
                        Can be used in an autocommand, example: >
                                :au BufEnter scratch stopinsert
<
                                        *replacing-ex* *:startreplace*
:startr[eplace][!]      Start Replace mode just after executing this command.
                        Works just like typing "R" in Normal mode.  When the
                        ! is included it acts just like "$R" had been typed
                        (ie. begin replace mode at the end-of-line).  Other-
                        wise replacement begins at the cursor position.
                        Note that when using this command in a function or
                        script that the replacement will only start after
                        the function or script is finished.
                        {not in Vi}
                        {not available when compiled without the +ex_extra
                        feature}

                                                        *:startgreplace*
:startg[replace][!]     Just like |:startreplace|, but use Virtual Replace
                        mode, like with |gR|.
                        {not in Vi}
                        {not available when compiled without the +ex_extra
                        feature}

==============================================================================
10. Inserting a file                                    *inserting-file*

                                                        *:r* *:re* *:read*
:r[ead] [++opt] [name]
                        Insert the file [name] (default: current file) below
                        the cursor.
                        See |++opt| for the possible values of [++opt].

:{range}r[ead] [++opt] [name]
                        Insert the file [name] (default: current file) below
                        the specified line.
                        See |++opt| for the possible values of [++opt].

                                                        *:r!* *:read!*
:[range]r[ead] !{cmd}   Execute {cmd} and insert its standard output below
                        the cursor or the specified line.  A temporary file is
                        used to store the output of the command which is then
                        read into the buffer.  'shellredir' is used to save
                        the output of the command, which can be set to include
                        stderr or not.  {cmd} is executed like with ":!{cmd}",
                        any '!' is replaced with the previous command |:!|.

These commands insert the contents of a file, or the output of a command,
into the buffer.  They can be undone.  They cannot be repeated with the "."
command.  They work on a line basis, insertion starts below the line in which
the cursor is, or below the specified line.  To insert text above the first
line use the command ":0r {name}".

After the ":read" command, the cursor is left on the first non-blank in the
first new line.  Unless in Ex mode, then the cursor is left on the last new
line (sorry, this is Vi compatible).

If a file name is given with ":r", it becomes the alternate file.  This can be
used, for example, when you want to edit that file instead: ":e! #".  This can
be switched off by removing the 'a' flag from the 'cpoptions' option.

Of the [++opt] arguments one is specifically for ":read", the ++edit argument.
This is useful when the ":read" command is actually used to read a file into
the buffer as if editing that file.  Use this command in an empty buffer: >
        :read ++edit filename
The effect is that the 'fileformat', 'fileencoding', 'bomb', etc. options are
set to what has been detected for "filename".  Note that a single empty line
remains, you may want to delete it.

                                                        *file-read*
The 'fileformat' option sets the <EOL> style for a file:
'fileformat'    characters         name                         ~
  "dos"         <CR><NL> or <NL>   DOS format
  "unix"        <NL>               Unix format
  "mac"         <CR>               Mac format
Previously 'textmode' was used.  It is obsolete now.

If 'fileformat' is "dos", a <CR> in front of an <NL> is ignored and a CTRL-Z
at the end of the file is ignored.

If 'fileformat' is "mac", a <NL> in the file is internally represented by a
<CR>.  This is to avoid confusion with a <NL> which is used to represent a
<NUL>.  See |CR-used-for-NL|.

If the 'fileformats' option is not empty Vim tries to recognize the type of
<EOL> (see |file-formats|).  However, the 'fileformat' option will not be
changed, the detected format is only used while reading the file.
A similar thing happens with 'fileencodings'.

On non-MS-DOS, Win32, and OS/2 systems the message "[dos format]" is shown if
a file is read in DOS format, to remind you that something unusual is done.
On Macintosh, MS-DOS, Win32, and OS/2 the message "[unix format]" is shown if
a file is read in Unix format.
On non-Macintosh systems, the message "[Mac format]" is shown if a file is
read in Mac format.

An example on how to use ":r !": >
        :r !uuencode binfile binfile
This command reads "binfile", uuencodes it and reads it into the current
buffer.  Useful when you are editing e-mail and want to include a binary
file.

                                                        *read-messages*
When reading a file Vim will display a message with information about the read
file.  In the table is an explanation for some of the items.  The others are
self explanatory.  Using the long or the short version depends on the
'shortmess' option.

        long            short           meaning ~
        [readonly]      {RO}            the file is write protected
        [fifo/socket]                   using a stream
        [fifo]                          using a fifo stream
        [socket]                        using a socket stream
        [CR missing]                    reading with "dos" 'fileformat' and a
                                        NL without a preceding CR was found.
        [NL found]                      reading with "mac" 'fileformat' and a
                                        NL was found (could be "unix" format)
        [long lines split]              at least one line was split in two
        [NOT converted]                 conversion from 'fileencoding' to
                                        'encoding' was desired but not
                                        possible
        [converted]                     conversion from 'fileencoding' to
                                        'encoding' done
        [crypted]                       file was decrypted
        [READ ERRORS]                   not all of the file could be read











posted on 2022-07-05 18:13  我在全球村  阅读(95)  评论(0编辑  收藏  举报