vim user manual 70

Embed Size (px)

Citation preview

  • 8/14/2019 vim user manual 70

    1/438

    1

    __ ___ ___ ____ ____

    | |\ / /\ / /\ / |\ / |\

    | || / / / /__/ / / || / ||

    | || / / / \__\/ / /| || / /| ||

    | || / / / ___ / / | || / / | ||

    | || / / / / /\ / / /| || / / /| ||

    | || / / / / / / / / / | ||/ / / | ||| || / / / / / / / / / | |/ / / | ||

    | || / / / / / / / / / | / / | ||

    | || / / / / / / / / / | / / | ||

    | ||/ / / / / / / / / | / / | ||

    | |/ / / / / / / / / |__/ / | ||

    | / / / / / / / / \__\/ | ||

    | / / / / / / / / | ||

    | / / / / / / / / | ||

    |__/ / /__/ / /__/ / |__||

    \__\/ \__\/ \__\/ \__\|

    : Bram Moolenaar

    : ZhaoRuFei

    : 7.0

    1

    mailto:[email protected]
  • 8/14/2019 vim user manual 70

    2/438

    2

    , Vim, Vim,

    ,

    Vim

    ,

    , , ,

    . . Vim,

    .

    , , .

    , , , Vim

    ,

    , . . ,

    , . Vim.

    , Vim, . , ,

    , . Vim.

    notepad, word, edit, ,. Vim , . BUG

    . , Vim(vi)

    , , , Vim.

    Vim.

    ,

    , . Vim. notepad, edit.

    , , , ? , UNIX,

    , :help xxx. . ,

    . . , , , , ,, .

    2

  • 8/14/2019 vim user manual 70

    3/438

    3

    . , , ,

    Mission Impossible . . Vim,

    . .

    i18ninternationalization, Vimthe teh, Vim, script,

    . Vim. Vim. Vim

    SHELL. Vim.

    Vim.

    , , , Vim

    ,Vim, , , , , ; LATEX, LATEX

    . , , , ,email

    , .

    The Vim user manual and reference manual are

    Copyright (c) 1988-2002 by Bram Moolenaar. This material may be distributed only subject to

    the terms and conditions set forth in the Open

    Publication License, v1.0 or later. The latest

    version is presently available at:

    http://www.opencontent.org/openpub/

    People who contribute to the manuals must agree

    with the above copyright notice.

    Vim.

    [email protected]

    2004/06/08

    3

    http://www.opencontent.org/openpub/mailto:[email protected]
  • 8/14/2019 vim user manual 70

    4/438

    4 0.2

    0.2

    0.20.1:

    2, ().

    Acrobat. Acrobat Reader

    56.

    34

    ===============

    ===============

    %

    ([email protected])gbk2uni.exe

    CTex

    4

  • 8/14/2019 vim user manual 70

    5/438

    5 6.3.0

    6.3.0

    1. 6.3.0?

    VIM6.3, 6.1 .. ,

    ?

    2. 6.3.00.2:

    (A) 0.10.2usr 21.txt, usr 22.txt, usr 29.txt, usr 45.txt4, 4,

    .

    (B) , shell, ,

    , :

    ex command:au BufRead *.tip setf tip

    .

    7. , Vim, ex command, 6:

    normal mode command

    Vimnormal, .

    normal mode commandgg=G

    shell command

    unixshell, windows OSDOSBOX. :

    shell commandenv LANG=de_DE.ISO_8859-1 vim

    Display

    , . :

    5

  • 8/14/2019 vim user manual 70

    6/438

    6 6.3.0

    Display:!make | &tee /tmp/vim215953.err

    gcc -g -Wall -o prog main.c sub.c

    main.c: In function 'main':

    main.c:6: too many arguments to function 'do_sub'

    main.c: At top level: main.c:10: parse error before '}' make: *** [prog] Error 1

    2 returned

    "main.c" 11L, 111C

    (3 of 6): too many arguments to function 'do_sub'

    Hit ENTER or type command to continue

    List

    , : Listr Insert

    o Normal"o""O"

    c 'textwidth'

    code, :

    codewhile i < b {

    i f a {

    b = c ;}

    }

    url, :

    URLhttp://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz

    (C) cmtt, computer modern

    typewriter, , cmr(computer modern roman).

    , LatexLATEX

    cmr, cmtt: LATEX. A1

    (D) , ,

    , , .

    1, "", """;" : ,, """, , ". , . , .

    6

    mailto:[email protected]
  • 8/14/2019 vim user manual 70

    7/438

    7 6.3.0

    URL. emailmail.

    (E) ...(LATEX), ...,"...", , , ', ,

    . /hello \hi, \hi.

    (F) , CTRL-N,

    (G) BUG, . , , , ...

    (H) , PDFHTML, HTMLbgcolor

    . , PDF. PDFTex.. .. .

    , PL(Public License,Piao Liang). windows. .

    3. TODO:

    , . , upquoteLATEX package, '. ,

    .fancyvrb, ---.

    , . LATEX, TMD, , ..

    7

  • 8/14/2019 vim user manual 70

    8/438

    8 7.0

    7.0

    0. 7.0"", Bram

    Beta, ,

    . , 7.0f Beta7.0 "".

    7.0release, 7.0.

    1. , :

    List- 50

    - :Omni

    - ,

    - : - Vim(Python)

    - Vim

    - Unicode

    -

    -

    - grep; ,

    - zip/tar

    -

    --- http://groups.yahoo.com/group/vimannounce/message/159

    2.

    , , VIM:colorscheme

    default, |41.1| |, . |.

    3. , , , .

    8

    http://groups.yahoo.com/group/vimannounce/message/159
  • 8/14/2019 vim user manual 70

    9/438

    9 LATEX

    LATEX

    0. LATEX. , , .

    1. fancyvrbVerbatim. .,

    . .

    2. fancyvrbVerbatim, , . ,, .

    3. CJK, ,.

    "s:count","other.vim"

    .

    , .COPY1

    4. ? :EMAIL [email protected] "a"

    ? .

    LATEXmarvosym\MVAt,

    : @. , , MAIL:\newcommand{\VimMailURL}[2]{\textcolor{VimURLColor}{\href{mailto:#1}{#1}}}

    email\VimMailURL, #1@\MVAt.

    :

    \newcommand{\VimMailURL}[2]{

    \texttt{}}

    Vim \VimMailURL{xxx}{yyy.zzz}

    \VimMailURL{xxx}{yyy.zzz}.

    1 : Vim , C/C++/Java. , "[a-zA-Z ][a-zA-Z0-9 ]*"

    9

    http://[email protected]/mailto:[email protected]
  • 8/14/2019 vim user manual 70

    10/438

    10 LATEX

    5. LATEX, ,

    . 6.3,, .

    , .

    10

  • 8/14/2019 vim user manual 70

    11/438

  • 8/14/2019 vim user manual 70

    12/438

    12

    0. ,.

    PDF? , AcrobatReader, RGB(255,255,242).

    1. HTMLTxt, HTML, . LATEX. docbook

    .

    2. Vim, ,, , . ,: . ,.

    3. PDFj, k, Acrobat Reader.

    4. , (, ,

    )Vim. .

    . Vim, .

    90%90% , . , , .

    . , .

    , . bash:

    shell commandfor i in usr*; do diff ../../vim70c/$i $i; done > tmp.txt

    gvim tmp.txt &

    , 7.0, ..

    5. , , , MAIL:

    12

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]
  • 8/14/2019 vim user manual 70

    13/438

    13

    , , , sort | uniq.

    MAIL, .

    13

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]
  • 8/14/2019 vim user manual 70

    14/438

    14 00

    *usr toc.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    :

    *user-manual*

    |usr 01.txt| |usr 02.txt| Vim|usr 03.txt| |usr 04.txt| |usr 05.txt| Vim|usr 06.txt| |usr 07.txt| |usr 08.txt| |usr 09.txt| GUI|usr 10.txt| |usr 11.txt| |usr 12.txt|

    |usr 20.txt| |usr 21.txt| |usr 22.txt| |usr 23.txt| |usr 24.txt| |usr 25.txt| |usr 26.txt| , |usr 27.txt| |usr 28.txt|

    14

    mailto:[email protected]
  • 8/14/2019 vim user manual 70

    15/438

    15 00

    |usr 29.txt| |usr 30.txt| |usr 31.txt| GUI|usr 32.txt|

    Vim

    |usr 40.txt| |usr 41.txt| Vim|usr 42.txt| |usr 43.txt| |usr 44.txt| |usr 45.txt|

    Vim

    |usr 90.txt| Vim

    |ref-manual.txt|

    HTMLPDF:

    http://vimdoc.sf.net

    , Vim.

    |usr 01.txt|

    |01.1| |01.2| |01.3| Vim|01.4|

    15

    http://vimdoc.sf.net/http://-/?-
  • 8/14/2019 vim user manual 70

    16/438

    16 00

    |usr 02.txt| Vim

    |02.1| Vim|02.2| |02.3|

    |02.4| |02.5| |02.6| |02.7| |02.8|

    |usr 03.txt|

    |03.1| Word

    |03.2| |03.3| |03.4| |03.5| |03.6| |03.7| |03.8| |03.9| |03.10|

    |usr 04.txt|

    |04.1| |04.2| |04.3| |04.4| Visual|04.5| |04.6| |04.7|

    |04.8| |04.9| |04.10|

    |usr 05.txt| Vim

    |05.1| vimrc|05.2| vimrc|05.3|

    16

    http://-/?-
  • 8/14/2019 vim user manual 70

    17/438

    17 00

    |05.4| plugin|05.5| |05.6| |05.7|

    |usr 06.txt|

    |06.1| |06.2| ?|06.3| |06.4| |06.5| |06.6|

    |usr 07.txt|

    |07.1| |07.2| |07.3| |07.4| |07.5| |07.6| |07.7|

    |usr 08.txt|

    |08.1| |08.2| |08.3| |08.4| |08.5| |08.6| |08.7| vimdiff|08.8|

    |usr 09.txt| GUI

    |09.1| GUI|09.2| |09.3| |09.4|

    17

  • 8/14/2019 vim user manual 70

    18/438

    18 00

    |usr 10.txt|

    |10.1| |10.2| |10.3|

    |10.4| |10.5| |10.6| |10.7| |10.8| |10.9|

    |usr 11.txt|

    |11.1| |11.2| ?|11.3| ?|11.4|

    |usr 12.txt|

    |12.1| word

    |12.2| "Last, First""First Last"|12.3| |12.4| |12.5| |12.6| 1

    |12.7| |12.8| word

    |usr 20.txt|

    |20.1| |20.2|

    1: Unix

    18

  • 8/14/2019 vim user manual 70

    19/438

    19 00

    |20.3| |20.4| |20.5|

    |usr 21.txt|

    |21.1| |21.2| shell|21.3| : viminfo|21.4| |21.5| |21.6|

    |usr 22.txt|

    |22.1| |22.2| |22.3| |22.4|

    |usr 23.txt|

    |23.1| DOS, Mac Unix|23.2| |23.3| |23.4| |23.5|

    |usr 24.txt|

    |24.1| |24.2| |24.3| |24.4| |24.5| |24.6| |24.7| |24.8| |24.9| |24.10| Normal

    19

    http://-/?-
  • 8/14/2019 vim user manual 70

    20/438

    20 00

    |usr 25.txt|

    |25.1| 1

    |25.2| |25.3|

    |25.4| |25.5|

    |usr 26.txt| ,

    |26.1| Visual|26.2| |26.3|

    |26.4

    |shellVim

    |usr 27.txt|

    |27.1| |27.2| |27.3| |27.4| |27.5|

    |27.6| |27.7| |27.8| |27.9|

    |usr 28.txt|

    |28.1| ?|28.2| |28.3| |28.4| |28.5| |28.6| |28.7| |28.8| |28.9| |28.10| ?

    1, !

    20

    mailto:[email protected]
  • 8/14/2019 vim user manual 70

    21/438

    21 00

    |usr 29.txt|

    |29.1| tags|29.2| |29.3|

    |29.4| |29.5|

    |usr 30.txt|

    |30.1| |30.2| C|30.3| |30.4|

    |30.5| |30.6|

    |usr 31.txt| GUI

    |31.1| |31.2| |31.3| |31.4| Vim|31.5|

    |usr 32.txt|

    |32.1| |32.2| |32.3|

    Vim

    Vim

    |usr 40.txt|

    |40.1| |40.2|

    21

  • 8/14/2019 vim user manual 70

    22/438

  • 8/14/2019 vim user manual 70

    23/438

    23 00

    |44.6| |44.7| |44.8| |44.9| |44.10|

    |44.11| |44.12|

    |usr 45.txt|

    |45.1| |45.2| |45.3| |45.4|

    |45.5|

    Vim

    Vimming.

    |usr 90.txt| Vim

    |90.1| Unix|90.2| MS-Windows|90.3| |90.4| |90.5| Vim

    : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    23

  • 8/14/2019 vim user manual 70

    24/438

    24 01

    *usr 01.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    Vim. Vim

    .

    |01.1| |01.2| |01.3| Vim

    |01.4|

    : |usr 02.txt| : |usr toc.txt|

    *01.1*

    Vim:

    1. , . .

    2. Vim.

    |notation|.

    .

    , . 1:

    ListCTRL-]

    CTRL-O

    1: , Vim HTML , click hereclick here"click here", , ; VimCTRL-], , , CTRL-]

    24

  • 8/14/2019 vim user manual 70

    25/438

    25 01

    , : |bars|. , 'number',":write", . CTRL-]CTRL-].

    ":help", |help.txt|.

    *01.2*

    Vim. ,

    (GUI), :

    |usr 90.txt|.

    *not-compatible*

    ViVim.

    Vi, , . vimrc

    . VIM, : Unix:

    ex command:!cp -i $VIMRUNTIME/vimrc_example.vim ~/.vimrc

    MS-DOS, MS-Windows, OS/2:

    ex command

    :!copy $VIMRUNTIME/vimrc_example.vim $VIM/_vimrc

    Amiga:

    ex command:!copy $VIMRUNTIME/vimrc_example.vim $VIM/.vimrc

    .

    Vim, 'compatible'.

    :ex command

    :set compatible?

    'nocompatible'. "compatible".. .:

    ex command:scriptnames

    25

  • 8/14/2019 vim user manual 70

    26/438

    26 01

    , ., 'compatible'.

    |vimrc||compatible-default|.

    : Vim. "evim"(easy vim) . Vim. Notepad. Insert, . , ,

    . |evim-keys|.

    *01.3* Vim

    (!)vimtutorVim. 30 , .

    Unix, Vim, :

    shell commandvimtutor

    MS-Windows"/Vim". $VIMRUNTIMEvimtutor.bat.

    , , .

    . ,

    , :

    shell commandvimtutor fr

    OpenVMS, VIM,

    :

    shell command@VIM:vimtutor

    , :

    1. . VIM():

    shell commandvim -u NONE -c 'e $VIMRUNTIME/tutor/tutor' -c 'w! TUTORCOPY' -c 'q'

    26

  • 8/14/2019 vim user manual 70

    27/438

    27 01

    "TUTORCOPY",

    , , :

    shell commandvim -u NONE -c 'e $VIMRUNTIME/tutor/tutor.fr' -c 'w! TUTORCOPY' -c 'q'

    vim -u NONE -c "set nocp" TUTORCOPY

    Vimhappy.

    3. del TUTORCOPY

    *01.4* *manual-copyright*

    Vim: c1988-2003 by BramMoolenaar. ""1.0

    , :

    http://www.opencontent.org/opl.shtml

    .

    *frombook*

    Steve OuallineVi IMproved - Vim(New Riders, ISBN:0735710015). "", (,

    , Vim 6.0). |frombook|.

    Steve OuallineNew RidersOPL! . ,

    .

    , . |iccf|.

    : |usr 02.txt| : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    27

    http://www.opencontent.org/opl.shtml
  • 8/14/2019 vim user manual 70

    28/438

    28 02Vim

    *usr 02.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    Vim

    ---

    Vim. . .

    , .

    |02.1| Vim|02.2| |02.3| |02.4| |02.5| |02.6| |02.7| |02.8|

    : |usr 03.txt| : |usr 01.txt| : |usr toc.txt|

    *02.1* Vim

    :

    shell commandgvim file.txt

    Vim.

    UNIX, MicrosoftWindows, MS-DOS.

    Vimfile.txt.

    , . :

    28

    http://-/?-
  • 8/14/2019 vim user manual 70

    29/438

  • 8/14/2019 vim user manual 70

    30/438

    30 02Vim

    "turtle". Insert

    Normal.Vim:

    Display+---------------------------------------+

    |A very intelligent turtle |

    |Found programming UNIX a hurdle ||~ |

    |~ |

    | |

    +---------------------------------------+

    ?

    , :

    ex command

    :set showmode

    . (, ).

    ().

    , "i" Vim --INSERT--.Insert.

    Display+---------------------------------------+

    |A very intelligent turtle |

    |Found programming UNIX a hurdle |

    |~ |

    |~ |

    |-- INSERT -- |

    +---------------------------------------+

    Normal"--INSERT--"

    1

    Vim---,

    . , Normal(Normal). , Vim,

    Normal2

    1: Normal--NORMAL--, 2: google,

    30

  • 8/14/2019 vim user manual 70

    31/438

    31 02Vim

    *02.3*

    Normal, :

    Listh

    j

    k

    l

    . lright?, : , .

    ()

    : . .

    . ? ,

    , ;hjkl.

    : h, l

    , j.

    k

    h l

    j

    , .

    "i"Insert , hjkl, Normal.|vimtutor|.

    , Hiroshi Iwatani:

    DisplayKomsomolsk

    ^

    |

    Huan Ho Los Angeles

    (Yellow river) |

    v

    Java (the island, not the programming language)

    31

  • 8/14/2019 vim user manual 70

    32/438

    32 02Vim

    *02.4*

    , "x". (

    , xxxx) , xxxxxxx(7x) "A very ".

    :

    Display+---------------------------------------+

    |intelligent turtle |

    |Found programming UNIX a hurdle |

    |~ |

    |~ |

    | |

    +---------------------------------------+

    , :

    DisplayiA young

    i(Insert), "A young", Insert(). :

    Display+---------------------------------------+

    |A young intelligent turtle |

    |Found programming UNIX a hurdle |

    |~ |

    |~ |

    | |

    +---------------------------------------+

    "dd". :

    Display+---------------------------------------+

    |Found programming UNIX a hurdle |

    |~ |

    |~ |

    |~ |

    | |

    +---------------------------------------+

    32

  • 8/14/2019 vim user manual 70

    33/438

    33 02Vim

    Vim,

    : "J". :

    Display

    A young intelligentturtle

    "J":

    DisplayA young intelligent turtle

    . , "u" , 1.. , "dd"

    , "u". :A:

    DisplayA young intelligent turtle

    xxxxxxx"A young". :

    Displayintelligent turtle

    "u". g, :

    Displayg intelligent turtle

    u:

    Displayng intelligent turtle

    u, :

    1: , , ...

    33

  • 8/14/2019 vim user manual 70

    34/438

    34 02Vim

    Displayung intelligent turtle

    oung intelligent turtle

    young intelligent turtle

    young intelligent turtle

    A young intelligent turtle

    : "u" , Vim Vi .|not-compatible|. VimVim. Vi, .

    , CTRL-R().

    , . CTRL-R, A:

    Displayyoung intelligent turtle

    , "U", .

    "U".

    DisplayA very intelligent turtle

    xxxx very

    A intelligent turtle

    xxxxxx turtle

    A intelligent

    "U"

    A very intelligent turtle

    "u""U"A intelligent

    "U", "u"CTRL-R

    . , , "u"CTRL-R.

    *02.6*

    34

  • 8/14/2019 vim user manual 70

    35/438

    35 02Vim

    Vim. |Q in|, .

    "i".

    ? . "a""i".

    ,

    Displayand that's not saying much for the turtle.

    Displayand that's not saying much for the turtle!!!

    , "x". turtlee. :

    normal mode commanda!!!

    e:

    Displayand that's not saying much for the turtle!!!

    "o", Insert

    . . :

    DisplayA very intelligent turtle

    Found programming UNIX a hurdle

    "o":

    normal mode commandoThat liked using Vim

    :

    35

  • 8/14/2019 vim user manual 70

    36/438

    36 02Vim

    DisplayA very intelligent turtle

    That liked using Vim

    Found programming UNIX a hurdle

    "O"(O).

    9. "kkkkkkkkk""9k".

    , . , , "a!!!"."3a!". 33.

    , 3"3x". .

    *02.7*

    Vim, "ZZ". Vim.

    : Vim,

    . "ZZ", Vim. .

    Vim. |07.4|.

    . . Vim:

    ex command:q!

    .

    , 3: (:), ; q, ;

    (.!) 1 2.

    , Vim.":q", Vim:

    1: Vim2: :!, , w!

    36

  • 8/14/2019 vim user manual 70

    37/438

    37 02Vim

    DisplayE37: No write since last change (use ! to override)

    Vim, ", ".

    , ":e!".

    *02.8*

    Vim, !

    ex command:help

    .

    .

    , ":help". Vim(): .

    . hljk .

    , "ZZ". , Vim.

    , (

    |help|). . CTRL-](), . (, Vim

    . CTRL-]word1.

    ,

    , CTRL-T(

    )

    . CTRL-O().

    *help.txt*. "*"().

    |29.1|.

    1 : , HTML,HTMLHTML

    Vimtag, Vim

    37

  • 8/14/2019 vim user manual 70

    38/438

    38 02Vim

    , :

    ex command:help {subject}

    "x", :

    ex command:help x

    , :

    ex command:help deleting

    Vim, :

    ex command:help index

    ( , CTRL-A),

    "CTRL-":

    ex command:help CTRL-A

    Vim1. Normal

    . , NormalCTRL-H:

    ex command:help CTRL-H

    , . Insert, "i ". CTRL-H:

    ex command:help i_CTRL-H

    Vim, . -.-t, :

    ex command:help -t

    1: InsertNormal

    38

  • 8/14/2019 vim user manual 70

    39/438

    39 02Vim

    Vim.

    , . 'number',:

    ex command:help 'number'

    |help-context|.

    . Insert, :

    ex command:help i_

    :

    DisplayE37: No write since last change (use ! to override)

    ID:

    ex command:help E37

    : |usr 03.txt| : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    39

  • 8/14/2019 vim user manual 70

    40/438

    40 03

    *usr 03.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    :

    , ,Vim. ., |Q lr|.

    |03.1| Word|03.2| |03.3| |03.4| |03.5| |03.6| |03.7| |03.8| |03.9| |03.10|

    : |usr 04.txt| : |usr 02.txt| : |usr toc.txt|

    *03.1* Word

    "w"word. Vim

    , "w"word.

    "3w"3words. :Display

    This is a line with example text

    --->-->->----------------->

    w w w 3w

    word"w"word. "b"1word:

    1: : backward

    40

  • 8/14/2019 vim user manual 70

    41/438

    41 03

    DisplayThis is a line with example text

  • 8/14/2019 vim user manual 70

    42/438

    42 03

    . .

    :

    Display^

    --------------->

    fh fy

    "fy"really.

    ; "3fl""foul" "l":

    DisplayTo err is human. To really foul up you need a computer.

    --------------------->

    3fl

    "F"2:

    1: "^", 2: : ,

    42

  • 8/14/2019 vim user manual 70

    43/438

    43 03

    DisplayTo err is human. To really foul up you need a computer.

  • 8/14/2019 vim user manual 70

    44/438

    44 03

    codeif (a == (b * c) / d)

    ---+---------------->

    %

    *03.5*

    CC++,

    :

    Displayprog.c:33: j undeclared (first use in this function)

    33. 33? "9999k"1"32j"32.

    , . "G"2. , .

    "33G"33. (|usr 30.txt|, :make)

    3, "G"."gg". "1G",

    .

    Display| first line of a file ^

    | text text text text |

    | text text text text | gg

    7G | text text text text |

    | text text text text

    | text text text text

    V text text text text |

    text text text text | G

    text text text text |

    last line of a file V

    1: 9999, C/C++,, , Vim.

    2: : GGo3: , Vim

    , ,

    44

  • 8/14/2019 vim user manual 70

    45/438

    45 03

    "%"1.

    "50%"2. "90%"3.

    , .

    ? :

    Display+---------------------------+

    H --> | text sample text |

    | sample text |

    | text sample text |

    | sample text |

    M --> | text sample text |

    | sample text |

    | text sample text |

    | sample text |

    L --> | text sample text |

    +---------------------------+

    : "H"Home, "M"Middle, "L"Last.

    *03.6*

    , :

    1. CTRL-G. ('ruler'):

    Display"usr_03.txt" line 233 of 650 --35%-- col 45-52

    , ,

    , . -, "col 2-9".

    , , 8, 9.

    2. 'number'4. :

    ex command:set number

    1: N2: , 50%3: Vim, ,

    ? :goto 34:

    45

  • 8/14/2019 vim user manual 70

    46/438

    46 03

    1, 2:

    ex command:set nonumber

    'number', "no"

    . , .

    Vim.

    . .

    3. 'ruler'. Vim

    ex command:set ruler

    'ruler',

    3

    *03.7* 4

    CTRL-U. . ,

    .

    CTRL-D, :

    1"", 2: :noboolean3 : , Vim set number,

    , , , :set nonumberruler, number, , |gq|

    4--

    46

    mailto:[email protected]
  • 8/14/2019 vim user manual 70

    47/438

    47 03

    Display+----------------+

    | some text |

    | some text |

    | some text |

    +---------------+ | some text || some text | CTRL-U --> | |

    | | | 123456 |

    | 123456 | +----------------+

    | 7890 |

    | | +----------------+

    | example | CTRL-D --> | 7890 |

    +---------------+ | |

    | example |

    | example |

    | example |

    | example |

    +----------------+

    CTRL-E()CTRL-Y(). :CTRL-E Extra. (MS-Windows, CTRL-Y

    ).

    ()CTRL-F. CTRL-B.CTRL-F1, CTRL-B2, !

    "j". . "zz"

    :

    Display+------------------+ +------------------+

    | some text | | some text |

    | some text | | some text |

    | some text | | some text |

    | some text | zz --> | line with cursor |

    | some text | | some text |

    | some text | | some text || line with cursor | | some text |

    +------------------+ +------------------+

    "zt"3, "zb"4.

    1: : Forward2: : Backward3: "zt"ttop, z,

    , ztZhuan Tie():-)4: : "b"bottom

    47

  • 8/14/2019 vim user manual 70

    48/438

    48 03

    , |Q sc|., 'scrolloff'.

    *03.8*

    "/string". "include",:

    normal mode command/include

    "/"1Vim,

    , . .

    .

    : .*[]^%/?~$ ,

    , . .

    . "n". #include:

    normal mode command/#include

    "n". #include . , "n". "3n"3. "/"

    2.

    "?""/", 3:

    1: Vim, 2

    : , normal, /, N, N,/, /text, nN, /N, :a 1 b

    a 2 b

    a 3 b

    a 4 b

    a 5 b

    a 6 b

    normal1, 2/\d3, 2, n, 4

    3: : Vim

    48

  • 8/14/2019 vim user manual 70

    49/438

  • 8/14/2019 vim user manual 70

    50/438

    50 03

    word"TheLongFunctionName",

    . "/TheLongFunctionName", . Vim.

    : word, "*".Vimword1.

    "#""*". :"3*"word.

    WORD

    "/the"Vim"there".

    "the":

    normal mode command/the\>

    "\", word., "\"word2. word"the":

    normal mode command/\

    "there""soothe"."*""#"wordword("g*""g#"

    word.)

    "nr".

    . "nr" "*" "n".

    . :

    ex command:set hlsearch

    "nr", Vim.

    , , 3

    :

    1: :word??: Visual select, yank, :let @/=@", n

    2: word, ,, 0

    3A: ? : |/\%

  • 8/14/2019 vim user manual 70

    51/438

    51 03

    ex command:set nohlsearch

    .

    ,

    1

    :

    ex command:nohlsearch

    'hlsearch'. .

    ,."n""N".

    . :

    ex command:set incsearch

    Vim.

    . :

    ex command

    :set nowrapscan

    . ,

    . 'wrapscan', .

    INTERMEZZO 2

    , Vim, Vim.

    |not-compatible|. :

    ex command:scriptnames

    , :

    1: , , 'hlsearch'

    2:

    51

  • 8/14/2019 vim user manual 70

    52/438

    52 03

    ex command:edit ~/.vimrc

    , Vim

    . :

    ex commandGo:set hlsearch

    "G" . "o" , ":set". . :

    normal mode commandZZ

    Vim, 'hlsearch'.

    *03.9*

    Vim.

    , . , , .

    .

    |usr 27.txt|.|pattern|.

    ^ . 16 . "include"

    include."^include"include.

    $. "was$"was.

    "x""the":

    Displaythe solder holding one of the chips melted and the

    xxx xxx xxx

    "/the$":

    Displaythe solder holding one of the chips melted and the

    xxx

    1:

    52

  • 8/14/2019 vim user manual 70

    53/438

    53 03

    "^the":

    Displaythe solder holding one of the chips melted and the

    xxx

    "/^the$", "the"

    . , "the ", .

    .. "c.m"cm, 1. :

    Display

    We use a computer that became the cummin winter.xxx xxx xxx

    ., .: . "ter."

    , :

    DisplayWe use a computer that became the cummin winter.

    xxxx xxxx

    "ter\."2.

    *03.10*

    "G", Vim

    .

    Vim

    .

    :

    normal mode command``

    , , 2

    1: , l, ., , , , .

    2: , ', : , `1

    53

  • 8/14/2019 vim user manual 70

    54/438

    54 03

    . `

    , `.

    , , . "/""n"(

    ). "fx""tx", word

    "w""e".

    , "j""k", .

    ``. CTRL-O

    (: Oolder). CTRL-I(: IO).

    3:

    normal mode command

    33G/^The

    CTRL-O

    331, "The". CTRL-O33. CTRL-O"33G"

    . CTRL-I33.CTRL-I"/^The":

    Display| example text ^ |

    33G | example text | CTRL-O | CTRL-I

    | example text | |

    V line 33 text ^ V

    | example text | |

    /^The | example text | CTRL-O | CTRL-I

    V There you are | V

    example text

    : CTRL-I .

    ":jumps". ">".

    1: , "",

    54

  • 8/14/2019 vim user manual 70

    55/438

    55 03

    Vim. "ma"

    "a".az26. . Vim.

    , `{mark}, {mark}.:

    normal mode command`a

    'mark(, )mark.`mark, `markmark

    .

    . ,

    .

    s(start):

    normal mode commandms

    e(end):

    normal mode commandme

    , :

    normal mode command's

    '', 'ee.

    s

    1

    ,

    e2

    , .

    :

    ex command:marks

    . :

    1: start2: end

    55

  • 8/14/2019 vim user manual 70

    56/438

    56 03

    List'

    "

    [

    ]

    : |usr 04.txt| : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    56

  • 8/14/2019 vim user manual 70

    57/438

    57 04

    *usr 04.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    ---

    . 3

    : , Visual.

    |04.1| |04.2| |04.3| |04.4| Visual|04.5| |04.6| |04.7| |04.8|

    |04.9|

    |04.10|

    : |usr 05.txt| Vim: |usr 03.txt| : |usr toc.txt|

    *04.1* 2"x".

    "4x"4.

    "dw"word. "w"

    word., "d", .

    , "4w"4word. "d4w"4word.

    57

  • 8/14/2019 vim user manual 70

    58/438

    58 04

    DisplayTo err is human. To really foul up you need a computer.

    ------------------>

    d4w

    To err is human. you need a computer.

    Vim. Vim

    word. "e"word, Vim1:

    DisplayTo err is human. you need a computer.

    -------->

    d2e

    To err is human. a computer.

    . "",

    "".

    "$". "d$". "", :

    DisplayTo err is human. a computer.

    ------------>

    d$

    To err is human

    : +. . "d".

    "4l""w". , .

    *04.2*

    "c", . "d", Insert. "cw"word. ,

    , wordInsert:

    1: ,

    58

  • 8/14/2019 vim user manual 70

    59/438

    59 04

    DisplayTo err is human

    ------->

    c2wbe

    To be human

    "c2wbe":

    Listc

    2w word(Insert)

    be

    Normal

    : "human". : ,

    , . "cw"."c"d, :"cw","ce",

    word. word. Vi. , Vim

    1.

    "dd", "cc".

    ().

    "d$", "c$"

    . "d$""a"Insert.

    +

    :

    List

    x dl()X dh()

    D d$()

    C c$()

    s cl()

    S cc()

    1: :

    59

  • 8/14/2019 vim user manual 70

    60/438

    60 04

    "3dw""d3w" 3word. , "3dw" word 3; "d3w"3word. .

    , , "3d2w"word, 3, 6word.

    "r". ."cl""s", "r"

    Normal.

    Displaythere is somerhing grong here

    rT rt rw

    There is something wrong here

    "r"

    .

    DisplayThere is something wrong here

    5rx

    There is something xxxxx here

    "r".

    . :"4r"41.

    *04.3*

    "."Vim. . , HTML, .

  • 8/14/2019 vim user manual 70

    61/438

    61 04

    DisplayTo generate a table of contents

    f< < --->

    df> > -->f< < --------->

    . df> --->f< < ------------->

    . df> -->

    ".", "u"CTRL-R

    . (: "."Normal, , , :

    Displayasdf 123

    asdf 1234

    1"cwxyz", Normal, :

    Displayasdf xyz

    1, ., :

    Displayasdf xyz

    :

    Displayasdf xyz4

    , 3xyz.)

    : "four""five". . :

    List/four "four"

    cwfive "five"

    n "four"

    . "five"

    n

    .

    61

  • 8/14/2019 vim user manual 70

    62/438

    62 04

    *04.4* Visual

    +.

    . Visual.

    "v"Visual. .. .

    , :

    DisplayThis is an examination sample of visual mode

    ---------->

    velllld

    This is an example of visual mode

    "l". "d".

    ,

    Visual. .

    , "V"Visual.

    . ..

    , "Vjj"3:

    Display+------------------------+

    | text more text |

    >> | more text more text | |

    selected lines >> | text text text | | Vjj>> | text more | V

    | more text more |

    +------------------------+

    , CTRL-VVisual. .

    62

  • 8/14/2019 vim user manual 70

    63/438

    63 04

    Displayname Q1 Q2 Q3

    pierre 123 455 234

    john 0 90 39

    steve 392 63 334

    "Q2", "Q2""Q". CTRL-VVisual."3j"3 , "w"

    word. ."h". "d".

    Visual, , "o"(: o other end)

    , . "o".

    , 4. "o", "O"

    1.

    "o""O"Visual Normal , Normal.

    *04.5*

    "d""x",

    . p(Vimput)

    . , "dd". "p". .

    Display

    a line a line a lineline 2 dd line 3 p line 3

    line 3 line 2

    , "p"

    . (word),"p"2.

    1: 42:

    63

  • 8/14/2019 vim user manual 70

    64/438

    64 04

    DisplaySome more boring try text to out commands.

    ---->

    dw

    Some more boring text to out commands.-------->

    welp

    Some more boring text to try out commands.

    PUTTING

    "P""p", . "dd", "P".

    "dw", "P"1.

    . .

    "p""P". ."dd""3p"3

    .

    , (

    ). , "the""teh". Vim, "teh"e"xp". : "x"e. "p"e

    , h.

    Displayteh th the

    x p

    *04.6*

    , , "u"."p".

    : yanking 2. "y". "p"3.

    1: 2: term:yanking3: """

    64

  • 8/14/2019 vim user manual 70

    65/438

    65 04

    YankingVim, "c"

    1, "y". "yank" "y".

    "y", "yw"word.

    ."y2w"word:

    Displaylet sqr = LongVariable *

    -------------->

    y2w

    let sqr = LongVariable *

    p

    let sqr = LongVariable * LongVariable

    "yw"word. , "ye".

    "yy", "dd". "D"

    , "Y". ! "y$".

    Displaya text line yy a text line a text line

    line 2 line 2 p line 2last line last line a text line

    last line

    *04.7*

    VimGUI(gvim), "Edit""Copy"

    . Visual, Edit/Copy. .

    . Vim2.

    , VimEdit/Paste. NormalInsert. Visual

    .

    1:change, copy2: , CopyNormalyank

    Copy, Vim *,yVim", Vim

    65

  • 8/14/2019 vim user manual 70

    66/438

    66 04

    "Cut" . "Copy",

    "Cut""Paste"(). Vim,

    .

    GUI, ,

    . "y"(yank)"p"(put), "*(, ). :

    normal mode command"*yy

    :

    normal mode command"*p

    Vim.

    |09.3||clipboard|.

    *04.8*

    , "dw". :

    "daw".

    1

    Displaythis is some example text.

    daw

    this is some text.

    "daw""d". "aw". : "aw"

    "A Word". "daw""Delete A Word", ,Word().

    Vim. +Visual. +.

    +,

    , . .

    "cis". :

    1 : Vim PERL : There is more than one way to do the samething

    66

  • 8/14/2019 vim user manual 70

    67/438

  • 8/14/2019 vim user manual 70

    68/438

    68 04

    12"interesting."

    5"text."1. "R". .

    InsertReplace.2, .

    .

    *04.10*

    ,

    . , NMN*M!

    |operator

    |.

    , . :

    Listx ("dl")

    X ("dh")

    D ("d$")

    dw word

    db worddiw word()

    daw word()

    dG

    dgg

    "c""d". "y"

    yank, .

    :

    1: , 12, .

    2: Replace

    68

    mailto:[email protected]
  • 8/14/2019 vim user manual 70

    69/438

    69 04

    List~ ,

    . (

    'tildeop' 1),

    .

    Visual.

    I Insert

    A Insert

    : |usr 05.txt| Vim : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    69

    http://-/?-
  • 8/14/2019 vim user manual 70

    70/438

    70 05Vim

    *usr 05.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    Vim

    , , ,

    , , , . . , : "" , "".

    Vim. Vim

    . plugin. .

    |05.1| vimrc|05.2| vimrc|05.3| |05.4| plugin|05.5| |05.6| |05.7|

    : |usr 06.txt| : |usr 04.txt| : |usr toc.txt|

    *05.1* vimrc *vimrc-intro*

    . , vimrc. Vim

    .

    vimrc(),:

    ex command:$MYVIMRC

    vimrc, |vimrc|, . ":version"Vim

    .

    70

  • 8/14/2019 vim user manual 70

    71/438

    71 05Vim

    UnixMacintosh--

    List~/.vimrc

    MS-DOSMS-Windows:List

    $HOME/_vimrc

    $VIM/_vimrc

    vimrc.

    . Vim'incsearch'. vimrc:

    ex command

    set incsearch

    Vim.

    Vim.

    , vim

    |usr 41.txt|.

    *05.2* vimrc *vimrc example.vim*

    vimrc(Vim

    )Vimnot-compatible(|not-compatible|). :

    List$VIMRUNTIME/vimrc_example.vim

    .

    ..

    ":help".

    ex commandset nocompatible

    , Vim

    , Vi. 'compatible'.

    ex commandset backspace=indent,eol,start

    71

  • 8/14/2019 vim user manual 70

    72/438

    72 05Vim

    VimInsert

    . Vim, , Insert.

    ex commandset autoindent

    Vim.

    , InsertNormalo.

    ex commandif has("vms")

    set nobackup

    else

    set backupendif

    Vim. VMS, .

    "~". |07.4|.

    ex commandset history=50

    .

    .

    ex commandset ruler

    Vim.

    ex commandset showcmd

    Vim . "2f", Vim

    "2f". "w", "2fw"Vim , "2f".

    72

  • 8/14/2019 vim user manual 70

    73/438

    73 05Vim

    Display+-------------------------------------------------+

    |text in the Vim window |

    |~ |

    |~ |

    |-- VISUAL -- 2f 43,8 17% |+-------------------------------------------------+

    ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^

    'showmode' 'showcmd' 'ruler'

    set incsearch

    1..

    ex command map Q gq

    . .

    "Q""gq". Vim5.0"Q" . , "Q"

    Ex, .

    ex commandvnoremap _g y:exe "grep /" . escape(@", \\/) . "/ *.c *.h"

    Visual, C. .

    . , .

    ex commandif &t_Co > 2 || has("gui_running")

    syntax on

    set hlsearch

    endif

    , . 'hlsearch'Vim. "if"

    . Vim|usr 41.txt|.

    *vimrc-filetype*

    1:. , , , . , , ,, ,

    73

  • 8/14/2019 vim user manual 70

    74/438

    74 05Vim

    ex commandfiletype plugin indent on

    Vim:

    1.

    , Vim."main.c", Vim".c""c"C.

    "#!/bin/sh", Vim"sh"shell.

    2. plugin

    1.

    "c", 'cindent'. Vimplugin., |write-filetype-plain|.

    3.

    , . Vim. |filetype-indent-on|'indentexpr'.

    ex command

    autocmd FileType text setlocal textwidth=78

    Vim, 78. . "autocmd FileType text"

    . "text" . "setlocal textwidth=78""textwidth" 78,.

    ex commandautocmd BufReadPost *

    \ if line("'\"") > 0 && line("'\"")

  • 8/14/2019 vim user manual 70

    75/438

    75 05Vim

    . |line-continuation|. Vim, .

    *05.3*

    Vim. . , "amount"

    "{amount}". ":map", VimF5:

    ex command:map i{ea}

    : , 4, 5 , F5ESC. .

    : F5. .

    i{ {. Insert.

    e word

    a} word}.

    , wordword , F5.

    , ;

    . Vim, 1, Vim.

    . , "\p"word, "\c" .

    :

    ex command:map p i(ea)

    :map \c i{ea}

    \p, Vim

    2

    1: , 2: |timeoutlen|

    75

  • 8/14/2019 vim user manual 70

    76/438

    76 05Vim

    ":map"().

    Normal . |40.1|.

    *05.4* plugin *add-plugin* *plugin*

    Vimplugin. pluginVim. plugin

    , .

    plugin:

    :

    :

    plugin, plugin|add-filetype-plugin|.

    plugin *standard-plugin*

    Vim, plugin, .plugin ,

    VimVim. |standard-plugin-list|plugin . |load-plugins|.

    *add-global-plugin*plugin, : 1.plugin. 2. .

    plugin

    ?

    1. Vim. $VIMRUNTIME/macros

    2. ,

    http://www.vim.org

    3. Vim|maillist|.

    4. : |write-plugin|.

    pluginsvimball, |vimball|.

    76

    http://www.vim.org/
  • 8/14/2019 vim user manual 70

    77/438

    77 05Vim

    plugins, |getscript|.

    plugin

    plugin, .

    copy

    plugin

    :

    List plugin

    Unix ~/.vim/plugin/

    PC and OS/2 $HOME/vimfiles/plugin or $VIM/vimfiles/plugin

    Amiga s:vimfiles/plugin

    Macintosh $VIM:vimfiles:plugin

    Mac OS X ~/.vim/plugin/

    RISC-OS Choices:vimfiles.plugin

    Unix(plugin):

    shell command mkdir ~/.vim

    mkdir ~/.vim/plugin

    cp /usr/local/share/vim/vim60/macros/justify.vim ~/.vim/plugin

    ! plugin

    .

    pluginsplugin/, plugin/. " /.vim/plugin/perl/*.vim"Perl plugins.

    plugin *add-filetype-plugin**ftplugins* 1

    Vim plugin, :

    ex command:filetype plugin on

    ! |vimrc-filetype|.

    plugin, ,plugin:

    1. plugin.

    1:

    77

  • 8/14/2019 vim user manual 70

    78/438

    78 05Vim

    2. .

    plugin

    plugin, plugin

    , , $VIMRUNTIME/macros, $VIMRUNTIME/ftplugin.

    plugin *ftplugin-name*

    plugin. plugin, "ftplugin"."stuff"plugin, Unix, :

    shell commandmv thefile ~/.vim/ftplugin/stuff.vim

    . , ,

    :

    shell command mv thefile ~/.vim/ftplugin/stuff_too.vim

    ,

    . "otherstuff.vim", Vim, "otherstuff".

    MS-DOS. plugin61,

    :

    shell command mkdir $VIM/vimfiles/ftplugin/fortran

    copy thefile $VIM/vimfiles/ftplugin/fortran/too.vim

    plugin:

    Listftplugin/.vim

    ftplugin/_.vim

    ftplugin//.vim

    1: MS-DOS8, 6, , plugin

    78

  • 8/14/2019 vim user manual 70

    79/438

    79 05Vim

    "". Unix

    "stuff":

    List~/.vim/ftplugin/stuff.vim

    ~/.vim/ftplugin/stuff_def.vim

    ~/.vim/ftplugin/stuff/header.vim

    plugin. plugin. pluginVim, plugin

    . ".vim".

    :

    List

    |filetype-plugins| plugin|load-plugins| Vimplugin|ftplugin-overrule| plugin.|write-plugin| plugin.|plugin-details| pluginpluginbug.|new-filetype|

    *05.5* *add-local-help* *matchit-install*

    , plugin.

    , plugin.

    "matchit.vim"plugin(Vim). plugin"%"HTML, Vim

    if/else/endif, , Vim().

    plugin: "matchit.txt". plugin. Vim, $VIMRUNTIME

    1. ("mkdir")2.

    1: MS-DOSMS-Windows2: MS-DOSMS-Windowsmkdirmd

    , , mkdirMS-DOS, MS-Windows Unix, MacOS X(DarwinUnix)

    79

  • 8/14/2019 vim user manual 70

    80/438

    80 05Vim

    ex command:!mkdir ~/.vim

    :!mkdir ~/.vim/plugin

    :!cp $VIMRUNTIME/macros/matchit.vim ~/.vim/plugin

    "cp"unix, MS-DOS"copy".

    'runtimepath', "doc".

    ex command:!mkdir ~/.vim/doc

    copy"doc".

    ex command:!cp \$VIMRUNTIME/macros/matchit.txt ~/.vim/doc

    , :|:helptags|tags1.

    ex command:helptags ~/.vim/doc

    ex command:help g%

    "g%".

    ex command:help local-additions

    .

    , .

    1 : tags / , C/C++/Java, foo, ,tags, tags-aware Vim/Emacs tags ,tags+ +. tags, man ctags, man etags

    80

  • 8/14/2019 vim user manual 70

    81/438

    81 05Vim

    |write-local-help|

    *05.6*

    , |options|. :

    ex command:options

    , , ,..

    . CTRL-O.

    . , "displaying text", :

    ex commandset wrap nowrap

    , :

    ex commandset nowrap wrap

    .

    'wrap'.

    'wrap'1.

    , , 2. ,

    :

    ex commandset so=0

    "$"0. "r5"5.

    . . 'scrolloff',

    .

    1: , options.txt2: Normal

    81

  • 8/14/2019 vim user manual 70

    82/438

  • 8/14/2019 vim user manual 70

    83/438

    83 05Vim

    .

    .

    1, :

    ex command

    :set whichwrap=b,s,

    Normal. Insert

    :

    ex command:set whichwrap=b,s,,[,]

    , 'whichwrap'.

    , . :

    ex command:set list

    ^I. $,

    .

    ., GUI, Vim

    . 'listchars':

    ex command:set listchars=tab:>-,trail:-

    ">---"2, "-", , ?

    'iskeyword'word:

    ex command:set iskeyword

    iskeyword=@,48-57,_,192-255 >

    1 : h, l , h, l , :setwhichwrap += l,h

    2: :set list

    83

  • 8/14/2019 vim user manual 70

    84/438

    84 05Vim

    "@". "48-57"ASCII4857

    , 09. "192-255".

    word, "w""upper-case"word:

    ex command:set iskeyword+=-

    :set iskeyword

    iskeyword=@,48-57,_,192-255,-

    Vim.

    "-=". , :

    ex command:set iskeyword-=_

    :set iskeyword

    iskeyword=@,48-57,192-255,-

    .

    Vim.

    , Vim, .

    'cmdheight'1.

    :

    ex command:set cmdheight=3

    , ..., .

    : |usr 06.txt| Using syntax highlighting : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    1:

    84

  • 8/14/2019 vim user manual 70

    85/438

    85 06

    *usr 06.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    0, 1, 24, 3, 0, 1, 2, 3456

    , 7. ;, m,

    echo -e "\e[1;32mthis is green \e[0;37m"

    . .

    ---[Linux/shell]

    . . , . .

    .

    |06.1| |06.2| ?|06.3| |06.4|

    |06.5| |06.6|

    : |usr 07.txt| : |usr 05.txt| Vim : |usr toc.txt|

    *06.1* :

    ex command:syntax enable

    . Vim

    . , , . .

    .

    85

  • 8/14/2019 vim user manual 70

    86/438

    86 06

    , ":syntax enable"

    |vimrc|.

    , |vimrc|:

    ex commandif &t_Co > 1

    syntax enable

    endif

    GUI, ":syntax enable"|gvimrc|.

    *06.2* ?

    :

    - .

    Vim , ,

    . . Unix , XFree86 xterm:|xfree-xterm|.

    -

    ,

    Vim

    .

    $TERM. , xterm:

    shell commandsetenv TERM xterm-color

    (shell):

    shell commandTERM=xterm-color; export TERM

    . , |xterm-color|, Vim(xterm).

    -

    Vim, . :

    ex command:set filetype

    86

  • 8/14/2019 vim user manual 70

    87/438

    87 06

    "filetype="Vim

    . :

    ex command:set filetype=fortran

    , $VIMRUNTIME/syntax . GUI

    Syntax. |modeline|, . ,

    Makefile ():

    ex command# vim: syntax=make

    . (.). |new-filetype|Vim.

    -

    1.

    , , |mysyntaxfile|.

    :

    -

    Vim . (

    ). (). Vim , .

    'background', :

    ex command:set background=dark

    :

    ex command:set background=light

    ":syntax enable" ,

    . 'background'":syntax reset"

    Vim.

    87

    http://-/?-
  • 8/14/2019 vim user manual 70

    88/438

    88 06

    -

    Vim. . 1, . CTRL-L.

    , .Tex

    |tex.vim|.

    *06.3*

    , . GUI

    Edit/Color Scheme . :

    ex command:colorscheme evening

    "evening". . $VIMRUNTIME/colors

    , |vimrc|":colorscheme".

    . :

    1. . Vim.Unix

    :

    ex command!mkdir ~/.vim/colors

    !cp $VIMRUNTIME/colors/morning.vim ~/.vim/colors/mine.vim

    Vim, $VIMRUNTIME.

    2. . :

    Listterm

    cterm

    ctermfg

    ctermbg

    gui GUI

    guifg GUI

    guibg GUI

    , :

    88

    http://-/?-
  • 8/14/2019 vim user manual 70

    89/438

    89 06

    ex command:highlight Comment ctermfg=green guifg=green

    "cterm""gui""bold""underline"., "bold,underline".

    |:highlight|.

    3. |vimrc|Vim:

    ex commandcolorscheme mine

    , :

    ex command:runtime syntax/colortest.vim

    .

    .

    *06.4*

    . ,:

    ex command:syntax clear

    ().

    :syn-off

    :

    ex command:syntax off

    , .

    :syn-manual

    , :

    89

  • 8/14/2019 vim user manual 70

    90/438

    90 06

    ex command:syntax manual

    , .

    , 'syntax':

    ex command:set syntax=ON

    *06.5*

    MS-WindowsVim:

    ex command:hardcopy

    ,

    . , Vim. Vim

    .

    Vim:

    List'printdevice'

    'printheader'

    'printfont'

    'printoptions'

    , Visual, :

    normal mode commandv100j:hardcopy

    "v"Visual. "100j"100, . ":hardcopy".

    Visual .

    Unix, PostScript, . , .

    HTML, NetscapeHTML.

    HTML:

    90

  • 8/14/2019 vim user manual 70

    91/438

    91 06

    ex command:source $VIMRUNTIME/syntax/2html.vim

    , .

    HTML

    .

    (

    , ):

    ex command:write main.c.html

    . ,Vim . |2html.vim|. HTML.

    , HTMLWeb,

    .

    *06.6*

    |usr 44.txt| |syntax| .

    : |usr 07.txt| : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    91

  • 8/14/2019 vim user manual 70

    92/438

    92 07

    *usr 07.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    , Vim. . .

    .

    |07.1| |07.2| |07.3|

    |07.4|

    |07.5| |07.6| |07.7|

    : |usr 08.txt| : |usr 06.txt| : |usr toc.txt|

    *07.1*

    Vim Vim. .

    ex command:edit foo.txt

    Vim.

    "foo.txt". Vim. , Vim

    :

    DisplayE37: No write since last change (use ! to override)

    : VimID, ,

    ID: :help E37

    92

  • 8/14/2019 vim user manual 70

    93/438

    93 07

    , . :

    ex command:write

    Vim, :

    ex command:edit! foo.txt

    , 1,

    :

    ex command:hide edit foo.txt

    , . |22.4|

    *07.2*

    Vim. :

    shell commandvim one.c two.c three.c

    Vim3. Vim

    . , :

    ex command:next

    ., , ":next". ":edit". , :

    ex command:next!

    .:

    1:

    93

  • 8/14/2019 vim user manual 70

    94/438

    94 07

    ex command:wnext

    1:

    ex command:write

    :next

    ?

    . "(2 of 3)". 3

    2.

    ,

    :

    ex command:args

    "arguments". :

    Displayone.c [two.c] three.c

    Vim.

    .

    :

    ex command:previous

    ":next", .

    :ex command

    :wprevious

    :

    ex command:last

    1: , , Vim.

    94

  • 8/14/2019 vim user manual 70

    95/438

    95 07

    :

    ex command:first

    ":wlast"":wfirst".

    ":next"":previous". 2:

    ex command:2next

    1

    , ":write".

    . , Vim, :

    ex command:set autowrite

    ,

    :

    ex command

    :set noautowrite

    Vim, . 3:

    ex command:args five.c six.c seven.h

    , shell:

    ex command:args *.txt

    Vim. ,

    , , ":args!"(!).

    1: , word, Vim,

    95

  • 8/14/2019 vim user manual 70

    96/438

    96 07

    ? *arglist-quit*

    , Vim.

    , Vim

    :Display

    E173: 46 more files to edit

    , . ()

    *07.3*

    , CTRL-^(^6). :

    ex command:args one.c two.c three.c

    one.c.

    ex command:next

    two.c. CTRL-^one.c. CTRL-^two.c , :

    ex command:next

    three.c. CTRL-^

    , ":next"":previous".

    "alternate". Vim, .

    , :

    normal mode command`"

    96

  • 8/14/2019 vim user manual 70

    97/438

    97 07

    .

    :

    normal mode command`.

    "one.txt". "x"."G", ":w", ":edit one.txt".`"Vim, . `."x"., `"`.. .

    4"mx", "`x". ,

    , . . .

    .

    . , . "foo.txt". ("50%")F

    (Ffoo):

    normal mode command

    50%mF

    "bar.txt"B(Bbar):

    normal mode commandGmB

    "F"foo.txt.

    , "B"bar.txt.

    Vim, ., 1

    . , H

    header, M Makefile, CC.

    , "marks":

    1: ,

    97

  • 8/14/2019 vim user manual 70

    98/438

    98 07

    ex command:marks M

    :

    ex command:marks MCP

    CTRL-OCTRL-I

    .

    *07.4*

    Vim

    .

    ,

    :

    ex command:set backup

    ~. data.txt,data.txt~.

    , :

    ex command:set backupext=.bak

    data.txt.bak.

    'backupdir'. . .

    .

    : 'backup''writebackup'

    , Vim. , . (

    , ).,

    , . ., .

    98

  • 8/14/2019 vim user manual 70

    99/438

    99 07

    'patchmode'Vim,

    :

    ex command:set patchmode=.orig

    data.txt, , Vim"data.txt.orig".

    , Vim"data.txt.orig"

    , "data.txt~"('backupext').

    'patchmode'(), .

    *07.5*

    ,

    . . "v". Visual.

    "y". yanks().

    , 1:

    ex command

    :edit thisfile/This

    vjjjj$y

    . , "p".

    ex command:edit otherfile

    /There

    p

    yank. "V"Visual. CTRL-V

    . "Y", "yaw"yank-a-word, .

    "p". "P"

    . Vim, .

    1: ,

    99

  • 8/14/2019 vim user manual 70

    100/438

    100 07

    ,, . .

    Vim. az26().

    f(f first):

    normal mode command"fyas

    "yas". Vim

    f"f. . 3l(l line):

    normal mode command"l3Y

    "l. b(bblock):

    normal mode commandCTRL-Vjjww"by

    "by. . w".

    f, l, b3. , :

    normal mode command"fp

    "fp.

    3. , 1.

    .

    , . . , wordw

    :

    normal mode command"wdaw

    1:

    100

  • 8/14/2019 vim user manual 70

    101/438

    101 07

    "d".

    , :

    ex command:write >> logfile

    "logfile". , log. .

    .

    , ":write"Visual. 10

    .

    *07.6*

    , .

    ":w". , .

    Vim:

    shell commandvim -R file

    Unix1:

    shell commandview file

    "file", ":w"

    .

    :

    DisplayW10: Warning: Changing a readonly file

    . .

    1: MS-WindowsMS-DOS

    101

  • 8/14/2019 vim user manual 70

    102/438

    102 07

    , .":write"!1.

    , :

    shell command

    vim -M file

    . , , :

    DisplayE21: Cannot make changes, 'modifiable' is off

    -MVim viewer.

    , :

    ex command:set modifiable

    :set write

    *07.7*

    . , . , :

    ex command:edit copy.c

    . .

    ":saveas" :

    ex command:saveas move.c

    Vim,

    . ":write", "move.c", "copy.c".

    , ,

    :

    1: !

    102

  • 8/14/2019 vim user manual 70

    103/438

    103 07

    ex command:file move.c

    Vim"not edited"1. Vim

    Vim

    .

    :

    DisplayE13: File exists (use ! to override)

    .

    : |usr 08.txt|

    : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    1: ""

    103

  • 8/14/2019 vim user manual 70

    104/438

    104 08

    *usr 08.txt* Vim 7.0.: 20060430

    VIM--- : Bram Moolenaar

    ,

    , .

    .

    |08.1| |08.2| |08.3| |08.4| |08.5| |08.6| |08.7| vimdiff|08.8| |08.9|

    : |usr 09.txt| GUI: |usr 07.txt| : |usr toc.txt|

    *08.1*

    :

    ex command:split

    :

    104

  • 8/14/2019 vim user manual 70

    105/438

    105 08

    Display+----------------------------------+

    |/* file one.c */ |

    |~ |

    |~ |

    |one.c=============================||/* file one.c */ |

    |~ |

    |one.c=============================|

    | |

    +----------------------------------+

    , . "====". . (

    )

    .

    , .

    CTRL-W w. ,

    . , .

    (CTRL-W CTRL-W, CTRL)

    ex command

    :close

    . , ":quit""ZZ", ":close" Vim, Vim.

    , ,

    ex command:only

    . . , 1,

    .

    1: gvim"E445:"

    105

  • 8/14/2019 vim user manual 70

    106/438

    106 08

    *08.2*

    :

    ex command:split two.c

    one.c,

    :

    Display+----------------------------------+

    |/* file two.c */ ||~ |

    |~ |

    |two.c=============================|

    |/* file one.c */ |

    |~ |

    |one.c=============================|

    | |

    +----------------------------------+

    , :

    ex command:new

    ":split"":new"1

    *08.3* ":split". ,

    . 3alpha.c2:

    ex command:3split alpha.c

    1: 17, 52: 3,

    106

  • 8/14/2019 vim user manual 70

    107/438

    107 08

    .

    : , .

    :

    normal mode commandCTRL-W +

    :

    normal mode commandCTRL-W -

    ,

    . "4 CTRL-W +"4.

    :

    normal mode command{height}CTRL-W _

    : {height}, CTRL-W(Shift-).

    , CTRL-W. 1

    Vim.

    . . .. ,

    .

    'winheight'. 'winminheight'

    , :'winwidth''winminwidth', .

    'equalalways', Vim

    .

    *08.4*

    1: WCTRL,

    107

  • 8/14/2019 vim user manual 70

    108/438

    108 08

    ":split".

    , :

    ex command:vsplit

    :

    :vsplit two.c

    :

    Display+--------------------------------------+

    |/* file two.c */ |/* file one.c */ |

    |~ |~ |

    |~ |~ |

    |~ |~ |

    |two.c===============one.c=============|| |

    +--------------------------------------+

    |.

    . .

    ":vnew", . :

    ex command:vertical new

    ":vertical"1.

    . (, ).

    ,

    . :

    DisplayCTRL-W h

    CTRL-W j

    CTRL-W k

    CTRL-W l

    CTRL-W t

    CTRL-W b

    1 : , :vertical echo"hello",

    108

  • 8/14/2019 vim user manual 70

    109/438

  • 8/14/2019 vim user manual 70

    110/438

  • 8/14/2019 vim user manual 70

    111/438

    111 08

    ex command:qall

    "quit all"1. ,

    Vim . . ":write", ":quit!".

    ,

    ex command:wall

    . "write all"2. ,

    . Vim.

    ":qall"":wall": :

    ex command:wqall

    Vim.

    , Vim:

    ex command:qall!

    ! !

    "-o"Vim:

    shell commandvim -o one.txt two.txt three.txt

    :

    1: 2:

    111

  • 8/14/2019 vim user manual 70

    112/438

    112 08

    Display+-------------------------------+

    |file one.txt |

    |~ |

    |one.txt========================|

    |file two.txt ||~ |

    |two.txt========================|

    |file three.txt |

    |~ |

    |three.txt======================|

    | |

    +-------------------------------+

    "-O".

    vim, ":all". ":vertical all".

    *08.7* vimdiff

    Vim

    ,

    .

    "main.c", , 'backup'

    , "main.c~".

    shell(Vim):

    shell commandvimdiff main.c~ main.c

    Vim.

    .

    112

  • 8/14/2019 vim user manual 70

    113/438

    113 08

    DisplayVV VV

    +-----------------------------------------+

    |+ +--123 lines: /* a|+ +--123 lines: /* a|

  • 8/14/2019 vim user manual 70

    114/438

    114 08

    1:

    ex command:edit main.c

    :vertical diffsplit main.c

    ":vertical". ,.

    patchdiff , 3 diff .patch . Vim patch:

    ex command:edit main.c

    :vertical diffpatch main.c.diff

    : patchpatch.

    , .

    , ().

    , . Vim2,

    .

    , :

    ex command:set noscrollbind

    , , :

    normal mode command]c

    . :

    1: diff??2:

    114

  • 8/14/2019 vim user manual 70

    115/438

    115 08

    normal mode command[c

    .

    .

    . . Vim.:

    ex command:diffupdate

    . ,

    . "main.c""main.c~". . :

    normal mode commanddp

    ,

    . "dp""diff put".

    . , "changed"

    .

    :

    normal mode commanddo

    , Vim

    . , Vim. "do""diff obtain"1

    |vimdiff|diff.

    *08.8*

    'laststatus':

    1: . "diff get") , ("dg",pending, , 3j4

    115

  • 8/14/2019 vim user manual 70

    116/438

    116 08

    List0

    1 ()

    2

    , .

    "s". ":tag"tag, ":stag"tag.

    NormalCTRL-W. CTRL-^

    , CTRL-W CTRL-^.

    'splitbelow'. 'splitright'

    , :

    List:leftabove {cmd}

    :aboveleft {cmd}

    :rightbelow {cmd}

    :belowright {cmd}

    :topleft {cmd} :botright {cmd}

    *08.9*

    windows, . .

    "thisfile".

    :

    ex command:tabedit thatfile

    "thatfile", Vim. :

    116

  • 8/14/2019 vim user manual 70

    117/438

  • 8/14/2019 vim user manual 70

    118/438

    118 08

    Display+-------------------------------------+

    | thisfile | /thisfile/ | thatfile __X| (thisfile is bold)

    |/* thisfile */ |

    |this |

    |this ||~ |

    |~ |

    |~ |

    | |

    +-------------------------------------+

    ":tab"Ex .

    . :

    ex commandtab help gt

    "gt".

    :

    List- \VimDQuote{gt}

    .

    - \VimDQuote{X}. .

    - - \VimDQuote{tabonly},

    |tab-page|.

    : |usr 09.txt| GUI : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    118

  • 8/14/2019 vim user manual 70

    119/438

    119 09GUI

    *usr 09.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    GUI

    Vim. GVimVim, . GUI , , . GVimVimGUI.

    |09.1| GUI|09.2| |09.3| |09.4|

    : |usr 10.txt| : |usr 08.txt| : |usr toc.txt|

    *09.1* GUI

    gVim. ,

    :

    shell commandgvim file.txt

    vim -g file.txt

    VimGUI. .

    Vim"file.txt". Vim. (ASCII

    !).

    119

  • 8/14/2019 vim user manual 70

    120/438

    120 09GUI

    Display+----------------------------------------------------+

    | file.txt + (~/dir) - VIM X |

  • 8/14/2019 vim user manual 70

    121/438

  • 8/14/2019 vim user manual 70

    122/438

    122 09GUI

    ex command:behave xterm

    :

    ex command:behave mswin

    UNIXxterm. Windows. , |:behave|. .

    XTERM

    List

    Visual

    List

    Visual

    , Shift

    . :

    List

    'mouse' Vim'mousemodel'

    'mousetime'

    'mousehide'

    'selectmode' Visual

    *09.3*

    122

  • 8/14/2019 vim user manual 70

    123/438

  • 8/14/2019 vim user manual 70

    124/438

    124 09GUI

    """",

    .

    , """

    ". "*"".

    "", Visual. , "V".

    "":

    normal mode command"*P

    "P". "p".

    "+"". ,

    :

    normal mode command"+y$

    , "y"yank, Vim.

    "":

    normal mode command"+P

    "", +*.

    *09.4*

    MS-WindowsX-Windows. . Visual. Visual, . : ,, .

    Select, (MS-Windows

    , ):

    ex command:set selectmode+=mouse

    124

  • 8/14/2019 vim user manual 70

    125/438

    125 09GUI

    . Visual.

    . , . Insert, .

    , Normal

    "hjkl", "w". Shift. (

    Shift). Visual. Shift+. .

    'selectmode'Select.

    : |usr 10.txt| : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    125

  • 8/14/2019 vim user manual 70

    126/438

    126 10

    *usr 10.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    4. . Visual

    . .

    |10.1| |10.2| |10.3|

    |10.4|

    |10.5| |10.6| |10.7| |10.8| |10.9|

    : |usr 11.txt| : |usr 09.txt| GUI : |usr toc.txt|

    *10.1*

    ".".

    ? Vim. 1

    1. "q{register}", {register}

    . az

    2

    2 3.

    3. q(q,

    ).

    "@{recording}".

    1: , :-)2: az3:

    126

  • 8/14/2019 vim user manual 70

    127/438

    127 10

    .

    :

    Liststdio.h

    fcntl.h

    unistd.hstdlib.h

    :

    List#include "stdio.h"

    #include "fcntl.h"

    #include "unistd.h"

    #include "stdlib.h"

    . :

    Listqa a

    ^

    i\#include " #include "

    $

    a" "

    j

    q

    , 3"@""@a"1,

    . :

    normal mode command3@a

    (

    4). , "@a"

    . "@a" , "@@". "@a". , "@b""@@"

    "@b".

    ".", , , ".". , "@a", , "."

    1: VIM

    127

  • 8/14/2019 vim user manual 70

    128/438

    128 10

    .

    . ,26. , 26.

    yank. .

    n. ., :

    ListG

    o

    "np n.

    .

    {edits} . 0

    "ny$ n

    dd

    "@n". (,

    n)

    .

    , .

    wordc.

    , word. :

    normal mode commandqC/wordq

    "qC", c, .

    yank, . , yank:

    normal mode command"aY

    , :

    128

  • 8/14/2019 vim user manual 70

    129/438

    129 10

    normal mode command"AY

    . a

    .

    *10.2* *find-replace*

    ":substitute" . :

    ex command:[range]substitute/from/to/[flags]

    [range]"from""to".

    "Professor""Teacher":

    ex command:%substitute/Professor/Teacher/

    : :substitute,

    ":s". .

    "%". , ":s". |10.2|.

    , ":substitute". ,

    DisplayProfessor Smith criticized Professor Johnson today.

    :

    DisplayTeacher Smith criticized Professor Johnson today.

    , "g"

    .

    129

  • 8/14/2019 vim user manual 70

    130/438

    130 10

    ex command:%s/Professor/Teacher/g

    :

    DisplayTeacher Smith criticized Teacher Johnson today.

    p(), ":substitute". c()":substitute". :

    ex command:%s/Professor/Teacher/c

    Vim"Professor":

    Displayreplace with Teacher (y/n/a/q/l/^E/^Y)?

    , 1:

    Listy ,

    n ,

    a , (?? :-) )

    q , l

    CTRL-E

    CTRL-Y

    "from".2. ,

    "the""these":

    ex command:s/^the/these/

    /, , /3:

    1: CTRL-E CTRL-Y. , , ,

    2: Vim, 3: /

    130

  • 8/14/2019 vim user manual 70

    131/438

    131 10

    ex command:s+one/two+one or two+

    *10.3*

    ":substitute"":",

    , . . :

    ex command:1,5s/this/that/g

    15. 15.

    :

    ex command:54s/President/Fool/

    . , "."1. ":write". , .

    :

    ex command:.write otherfile

    1. ? "$"., yesno:

    ex command:.,$s/yes/no/

    , "%", "1,$".

    , "grey""gray"."grey". "Chapter"

    , :

    ex command:?^Chapter?,/^Chapter/s=grey=gray=g

    1:

    131

  • 8/14/2019 vim user manual 70

    132/438

    132 10

    , . "?^Chapter?" ,

    "/^Chapter/". liao/, ":s""=".

    : "grey". , ?

    : :

    ex command/Chapter/-1

    1. 2:

    ex command

    /Chapter/+2

    :

    ex command:.+3,$-5

    3, 61.

    : , .

    3. "mt", "mb". :()

    ex command:'t,'b

    VisualVisual":",

    :

    ex command:'

  • 8/14/2019 vim user manual 70

    133/438

    133 10

    : VisualCTRL-V, . Vim.

    '

  • 8/14/2019 vim user manual 70

    134/438

    134 10

    ex command:g+//+s/foobar/barfoo/g

    ":g", ":global", ":s"":substitute". .

    /, . "foobar""barfoo".

    .

    . ":substitute", .

    , "//", "//""foobar",1

    .":substitute",

    Vim.

    .

    *10.5* Visual block

    CTRL-V,

    . Vim

    2.

    Visual block"$", .

    . "j","h".

    "Istring", . CTRL-VVisual block.

    . I, . ,

    . , . :

    1: :puts("foobar"); // this line contains a foobar

    2: "$" ,

    134

  • 8/14/2019 vim user manual 70

    135/438

    135 10

    Displayinclude one

    include two

    include three

    include four

    "one""o", CTRL-V. "3j"3, "four". 4

    . :

    normal mode commandImain.

    :

    Displayinclude main.one

    include main.two

    include main.three

    include main.four

    , . , "long""long",

    2:

    DisplayThis is a long line

    short

    Any other long line

    ^^^^ selected block

    "Ivery

  • 8/14/2019 vim user manual 70

    136/438

    136 10

    "A""I", .

    , IAVisual.

    "A": "$"

    . "A". ,

    "$A XXX", :

    DisplayThis is a long line XXX

    short XXX

    Any other long line XXX

    "$", Vim.

    1, .

    Visual block"c",

    Insert, . 2 , "long"

    , "c LONG ", :

    DisplayThis is a _LONG_ line

    short

    Any other _LONG_ line

    "I": , , .

    "C"3 ,

    Insert, 4. , "Cnew text ", :

    Display

    This is a new textshort

    Any other new text

    1: "$", :This is a long line XXX

    short XXX

    Any other long line XXX

    2: 3: 4: ,

    136

  • 8/14/2019 vim user manual 70

    137/438

    137 10

    , "long",

    . . , .

    Visual block:

    List~ (a -> A, A -> a)

    U (a -> A, A -> A)u (a -> a, A -> a)

    "r". , "rx":

    Display

    This is a xxxx lineshort

    Any other xxxx line

    : , 25'virtualedit'.

    ">""shift "1, . . , ">"

    :

    DisplayThis is a long line

    short

    Any other long line

    'shiftwidth'. 4:

    ex command:set shiftwidth=4

    "", ,

    "shift ", 2.

    1 : "shift ":set sw=N , N , :h'sw'

    2: , , ,

    137

  • 8/14/2019 vim user manual 70

    138/438

    138 10

    "J". , , ,1

    . 2.

    . "J"

    DisplayThis is a long line short Any other long line

    "J"Visual block. "v"

    "V"3

    , "gJ""J"

    *10.6*

    e-mail, .

    ":read {filename}" . . :

    DisplayHi John,

    Here is the diff that fixes the bug:

    Bye, Pierre.

    , :

    ex command:read patch

    "patch", :

    DisplayHi John,

    Here is the diff that fixes the bug:2c2

    < for (i = 0; i for (i = 0; i < length; ++i)

    Bye, Pierre.

    1: , , /^\s\+//s+$/, TODO:

    2: ??3:

    138

  • 8/14/2019 vim user manual 70

    139/438

    139 10

    ":read".

    . ":$r patch""patch". ? 0.0. , . "read"

    :ex command

    :0read patch

    "patch".

    , ":write". . :

    ex command:.,$write tempo

    "tempo", "tempo", , Vim., "write"!

    ex command:.,$write! tempo

    : !":write", .. 1.

    , . :

    ex command:.write collection

    , :

    ex command:.write >>collection

    ">>"Vim"collection", . , .

    1:

    139

  • 8/14/2019 vim user manual 70

    140/438

  • 8/14/2019 vim user manual 70

    141/438

    141 10

    . ,

    . , 1. ".", .

    *10.8* 2

    section header3. "section". "gU". 4

    "gu""gU":

    Displayguw

    SECTION header ----> section header

    "g~", , . , ,

    Visual5. . , "d", "dd". , "gugu"

    . , "guu". "gUgU""gUU", "g~g~""g~ "6. :

    Displayg~~

    Some GIRLS have Fun ----> sOME girls HAVE fUN

    *10.9*

    Vim7.

    .

    "!{motion}{program}"1: Vim,

    , , /\w\+/2: 3: 4: section5: Vim, operator commandmotion ,

    text object?? "", , a + b ,

    6: , , "3dd"3

    7:

    141

  • 8/14/2019 vim user manual 70

    142/438

    142 10

    . , {program}, {motion}, {motion}.

    UNIX, , . sort.

    input.txtoutput.txt. (

    UNIXMicrosoft Windows).

    shell commandsort < input.txt > output.txt

    Vim, . 1-5, 1. :

    normal mode command!5G

    "!"Vim. Vim, . "5G"

    Vim5, Vim1()5.

    , Vim1., "sort". , :

    normal mode command

    !5Gsort

    sort5. 5.

    Displayline 55 line 11

    line 33 line 22

    line 11 --> line 33

    line 22 line 44

    line 44 line 55

    last line last line

    "!!". Unix"date". "!!date""date"

    . .

    ?

    1: {motion}VimNormal, ,, Normal,Normal

    142

  • 8/14/2019 vim user manual 70

    143/438

    143 10

    Vimshell.

    , :

    'shell' Vimshell

    'shellcmdflag' shell

    'shellquote' shell

    'shellxquote' shell

    'shelltype' shell(Amiga)1

    'shellslash' (MS-Windows)

    'shellredir'

    Unix, shell: "sh"

    "csh". Vim'shell'"csh"

    ,

    MS-Windows, shell,

    . .

    : Unix:

    ex command:read !ls

    MS-Windows:

    ex command:read !dir

    "ls""dir"Vim. , "!"Vim.

    .

    Vim

    :

    ex command:0read !date -u

    UTC(date

    "-u")"!!date", "!!date", ":read !date".

    143

    http://-/?-
  • 8/14/2019 vim user manual 70

    144/438

    144 10

    Unix"wc", , .

    , :

    ex command:write !wc

    "write", , "!".

    . 1:

    Display4 47 249

    "wc"3. 4,

    47, 249.

    :

    ex command:write! wc

    "wc"2. !

    , .

    Vim, . Vim:

    normal mode commandCTRL-L

    : |usr 11.txt| : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    1:2:

    144

  • 8/14/2019 vim user manual 70

    145/438

    145 11

    *usr 11.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    ? ? ! Vim

    . Vim.

    |11.1| |11.2| ?

    |11.3

    |?

    |11.4|

    : |usr 12.txt| : |usr 10.txt| : |usr toc.txt|

    *11.1*

    , (), Vim"-r":

    shell commandvim -r help.txt

    Vim(). , (

    ):

    DisplayUsing swap file ".help.txt.swp"

    Original file "~/vim/runtime/doc/help.txt"

    Recovery completed. You should check if everything is OK.

    (You might want to write out this file under another name

    and run diff with the original file to check for changes)

    Delete the .swp file afterwards.

    , :

    145

  • 8/14/2019 vim user manual 70

    146/438

    146 11

    ex command:write help.txt.recovered

    .

    Vimdiff|08.71|. (

    ). (Vim )

    Vim, , .

    . Vim4, 200. 'updatetime''updatecount'. Vim,.

    ,

    "":

    shell commandvim -r ""

    , Vim.

    *11.2* ?

    Vim. . , :

    shell commandvim -r

    Vim. 1.

    , 2.

    :

    1: ~foo/, readme.txt, .readme.txt.swp , Vim /tmp readme.txt

    2:

    146

    http://-/?-
  • 8/14/2019 vim user manual 70

    147/438

    147 11

    DisplaySwap files found:

    In current directory:

    1. .main.c.swp

    owned by: mool dated: Tue May 29 21:00:25 2001

    file name: ~mool/vim/vim6/src/main.c modified: YES

    user name: mool host name: masaka.moolenaar.net

    process ID: 12525

    In directory ~/tmp:

    -- none --

    In directory /var/tmp:

    -- none --

    In directory /tmp:

    -- none --

    , Vim, .

    .

    , .

    ,

    . Vim.

    :

    shell commandvim -r .help.txt.swo

    .

    , Vim. 'directory'Vim.

    : Vim 'dir' "filename.sw?" . (

    'shell' ), Vim "filename.swp" . , .

    *11.3* ?

    147

  • 8/14/2019 vim user manual 70

    148/438

    148 11

    Vim,. ,

    Vim. :

    DisplayE325: ATTENTION

    Found a swap file by the name ".main.c.swp"

    owned by: mool dated: Tue May 29 21:09:28 2001file name: ~mool/vim/vim6/src/main.c

    modified: no

    user name: mool host name: masaka.moolenaar.net

    process ID: 12559 (still running)

    While opening file "main.c"

    dated: Tue May 29 19:46:12 2001

    (1) Another program may be editing the same file.

    If this is the case, be careful not to end up with two

    different instances of the same file when making changes.Quit, or continue with caution.

    (2) An edit session for this file crashed.

    If this is the case, use ":recover" or "vim -r main.c"

    to recover the changes (see ":help recovery").

    If you did this already, delete the swap file ".main.c.swp"

    to avoid this message.

    Vim.

    , . :

    1. Vim. "processID". :

    Displayprocess ID: 12559 (still running)

    "(still running)".

    Unix. , . .

    .

    Vim, , . , . , Vim.

    2. Vim.

    Vim. , :

    Display modified: YES

    148

  • 8/14/2019 vim user manual 70

    149/438

    149 11

    Vim, .

    ,

    . (, ), , (

    , ). Vim:

    DisplayNEWER than swap file!

    :

    Display[cannot be read]

    ? .

    , .

    0. .

    . 1, . ,

    , "read error". (

    ).

    .

    . (), . ,

    .

    ?

    VIM, :

    DisplaySwap file ".main.c.swp" already exists!

    [O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort, (D)elete it:

    O .

    .

    , .

    1: ?

    149

  • 8/14/2019 vim user manual 70

    150/438

    150 11

    E .

    ! Vim, .Vim, , .

    R .

    .

    Q .

    . Vim. Vim, Vim. , Vim

    1. , , .

    A .

    , , . .

    D .

    . , , . Unix

    .

    (Vim),

    . :

    ex command:recover

    Vim.

    . Vim.

    , 'shortmess'

    "A"2. , .

    *11.4*

    1: Vim2: AATTENTION

    150

  • 8/14/2019 vim user manual 70

    151/438

  • 8/14/2019 vim user manual 70

    152/438

    152 12

    *usr 12.txt* Vim 7.0.: 20060424

    VIM--- : Bram Moolenaar

    , Vim. .

    .

    |12.1| word|12.2| "Last, First""First Last"

    |12.3| |12.4| |12.5| |12.6| 1

    |12.7| |12.8| word

    : |usr 20.txt| : |usr 11.txt| : |usr toc.txt|

    *12.1* word

    word:

    ex command:%s/four/4/g

    "%". "g"

    .

    "thirtyfour",

    , "thirty4". . "\

  • 8/14/2019 vim user manual 70

    153/438

    153 12

    , "fourty". "\>"

    word:

    ex command:%s/\/4/g

    , "four", . , "c"

    :

    ex command:%s/\/4/gc

    . , . .

    C++, ".cpp". "GetResp""GetAnswer".

    vim *.cpp Vim, : C++. .

    qq , q.

    :%s/\/GetAnswer/g .

    :wnext

    q @q q .

    ":wnext. .

    999@q 1

    , ":wnext"

    "next". , 2.

    : , .

    .

    : .cpp"GetResp",, . "e":

    2: Vim,

    153

    http://-/?-
  • 8/14/2019 vim user manual 70

    154/438

    154 12

    ex command:%s/\/GetAnswer/ge

    "e"":substitute"

    .

    *12.2* "Last, First""First Last"

    :

    DisplayDoe, John

    Smith, Peter

    :

    DisplayJohn Doe

    Peter Smith

    . Vim:

    ex command:%s/\([^,]*\), \(.*\)/\2 \1/

    . . "%": .

    "/from/to/". "from""to"."from":

    Display\([^,]*\), \(.*\)

    \( \), "Last" \( \) [^,]

    * ", " ,\( \), "First" \( \)

    . *

    "to""\2""\1". Vim

    . \( \). "\2"

    154

  • 8/14/2019 vim user manual 70

    155/438

    155 12

    "\( \)", "First", "\1"\( \)

    ,"Last" .

    9. "\0". . |sub-replace-special|.

    *12.3*

    Makefile, :

    DisplayOBJS = \

    version.o \

    pch.o \

    getopt.o \

    util.o \

    getopt1.o \

    inp.o \

    patch.o \

    backup.o

    sort:

    ex command/^OBJS

    j

    :.,/^$/-1!sort

    , "OBJS", , sort. Visual"!sort". ,

    .

    :

    DisplayOBJS = \

    backup.o

    getopt.o \

    getopt1.o \

    inp.o \

    patch.o \

    pch.o \

    util.o \

    version.o \

    155

  • 8/14/2019 vim user manual 70

    156/438

    156 12

    .

    ! "backup.o",1

    "A \".

    ,

    .

    *12.4*

    |:global||:move|, . :

    ex command:global/^/m 0

    :

    ex command:g/^/m 0

    "^"().

    |:move|0, .|:global|.

    ,

    2

    . "mt".3:

    ex command:'t+1,.g/^/m 't

    *12.5*

    --- Vim

    .

    , :

    normal mode commandg CTRL-G

    1: Makefile2: , Join3: , : :10,20g/^/m9

    156

  • 8/14/2019 vim user manual 70

    157/438

    157 12

    . "g"

    , .

    :

    Display

    Col 1 of 0; Line 141 of 157; Word 748 of 774; Byte 4489 of 4976

    word(748),

    word(774).

    ,

    "g CTRL-G", "g CTRL-G". word,

    . , .Visual, . "g CTRL-G". :

    DisplaySelected 5 of 293 Lines; 70 of 1884 Words; 359 of 10928 Bytes

    , , |count-items|.

    *12.6* 1

    VimshellC,

    (Unix). ::

    normal mode commandK

    Vim"man". . ( "more").

    Vim.

    .

    manVim, manplugin:

    ex command:source $VIMRUNTIME/ftplugin/man.vim

    vimrc. ":Man"2

    man:

    1: Unix2ManVim, unixman,

    157

  • 8/14/2019 vim user manual 70

    158/438

    158 12

    ex command:Man csh

    , .

    . "CTRL-W w"

    .

    , ,

    3"echo":

    ex command:Man 3 echo

    man, man

    "word(1)",CTRL-]. ":Man"

    1

    man, :

    normal mode command\K

    (, ). , "strstr()":

    codeif ( strstr (input, "aap") == )

    "strstr", "\K". Vimstrstr() man2.

    *12.7*

    ,

    . :

    ex command:%s/\s\+$//

    1 : (1) man CTRL-] , "word(1)" man, man. Vimman, man,. (2) man"word.~" ., . (3) :vertical Manls,

    2: man.vim, "K"

    158

  • 8/14/2019 vim user manual 70

    159/438

    159 12

    "%", . ":substitute"

    "\s\+$"., |usr 27.txt|.

    ":substitute""to":"//".

    , .

    . . ! , :

    normal mode command/

    , , . "/". "x"

    . ,. "n". .

    *12.8* word

    UNIX, Vimgrep

    . , . .

    , "frame counter"C:

    shell commandvim \VimBacktick{}grep -l frame_counter *.c\VimBacktick{}

    . grep. "-l", . "frame counter". ,

    (: grepVim1.)

    2. UNIXshell:, , . grep

    , Vim. ":next"":first"3.

    1: Mastering the Regular Expression

    2: ":substitute"\13: MS-DOSgrep. Cygwin

    grep. SHELL`

    159

  • 8/14/2019 vim user manual 70

    160/438

    160 12

    word. .

    Vim

    . C"error string", :

    ex command:grep error_string *.c

    Vim (*.c) "error string"."error string"

    . (), ":cnext". , ":cprev", ":clist"

    .

    ":grep"grep(Unix)findstr(Windows).'grepprg'.

    : |usr 20.txt| : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    160

  • 8/14/2019 vim user manual 70

    161/438

  • 8/14/2019 vim user manual 70

    162/438

    162 20

    List

    CTRL-B CTRL-E

    : ( Shift )( CTRL )

    . ShiftCTRL.

    .

    , . , CTRL-W.

    normal mode command/the fine pig

    CTRL-W

    /the fine

    CTRL-U. .

    .

    :

    normal mode command/the fine pig

    2(, 8)"fine". ,

    "great".

    normal mode command/the greatpig

    162

  • 8/14/2019 vim user manual 70

    163/438

    163 20

    , , . ,

    "t"(). , :

    normal mode command/the great pig

    , .CTRL-C .

    : "". ,

    Vi ! bug, Vim .

    'cpoptions'VimVi.

    (Vi)Vi.CTRL-Ca.)

    a: : CTRL-W, , CTRL-W CTRL-C

    , . ":""/".

    *20.2*

    . ":substitute"":s". Vim,

    .

    ? 26, ":set"":s",":s"":set", ":set" ":se".

    , .

    ? , good good study. , :

    Display:s[ubstitute]

    ":substitute"":s". . ":su"":sub".

    , .":function"":fu".

    163

  • 8/14/2019 vim user manual 70

    164/438

    164 20

    , ":fun". (Vim":funny",

    ":fun").

    Vim. . ":w"(":write")":r"(":read")

    .

    ":end", ":endif", ":endwhile""endfunction.

    .

    . , , ,'autoindent''ai'. :

    normal mode command

    :set autoindent:set ai

    |option-list|.

    *20.3*

    ViVim. ,

    1.

    3:

    Listinfo.txt

    intro.txt

    bodyofthepaper.txt

    :

    ex command:edit bodyofthepaper.txt

    . :

    ex command:edit b

    1: : ", , !" --

    164

  • 8/14/2019 vim user manual 70

    165/438

    165 20

    , ? ."b". Vim"b"., Vim.

    :

    ex command:edit i

    Vim, :

    ex command:edit info.txt

    Vim. (

    ). , :

    ex command:edit intro.txt

    , , ,,.

    :

    ex command:edit i

    . Vim, CTRL-P

    .

    Display -->

    :edit i :edit info.txt :edit intro.txt

  • 8/14/2019 vim user manual 70

    166/438

    166 20

    , ":set info.txt"? Vim

    . . Vim":set", .

    , Vim. ,

    :

    ex command:set isk

    :

    ex command:set iskeyword

    "=":

    ex command:set iskeyword=@,48-57,_,192-255

    Vim, .

    Vim. ., Vim

    , .

    (^I).

    , : CTRL-D.

    CTRL-D:

    ex command:set is

    :

    ex command:set is

    incsearch isfname isident iskeyword isprint

    :set is

    Vim. .

    , . ,

    .

    166

  • 8/14/2019 vim user manual 70

    167/438

    167 20

    , "incsearch" "is"."is". ()Vim,

    .

    CTRL-L. ":edit i", "info.txt""info backup.txt", ":edit info".

    'wildmode'.

    'wildmenu'.'suffixes', .

    'wildignore'1.

    |cmdline-completion|

    *20.4*

    3.

    .

    4. "/""?", "/""?", . input()

    . |cmdline-history|

    ":set",10":set". ":"10.

    :

    ex command:se

    Vim"se". ":set"

    . 10(10":set").

    ..

    ,

    . CTRL-U.

    1: (1)Vim, , (2)Vim, .,

    167

  • 8/14/2019 vim user manual 70

    168/438

    168 20

    , :

    ex command:history

    . , 1:

    ex command:history /

    CTRL-P, . , CTRL-N. CTRL-Pprevious, CTRL-NNext 2

    *20.5*

    3 .

    . . . .

    4:

    normal mode commandq:

    Vim(). , :

    1: : map, autocommand, tags, ,

    2: , CTRL-PCTRL-N, shell. emacs, ,

    3: : , Vim

    4: normal

    168

  • 8/14/2019 vim user manual 70

    169/438

    169 20

    Display+-------------------------------------+

    |other window |

    |~ |

    |file.txt=============================|

    |:e c ||:e config.h.in |

    |:set path=.,/usr/include,, |

    |:set iskeyword=@,48-57,_,192-255 |

    |:set is |

    |:q |

    |: |

    |command-line=========================|

    | |

    +-------------------------------------+

    Normal. "hjkl". "5k"":e config.h.in" . "$h" "in""i", "cwout".

    :

    ex command:e config.h.out

    . .

    . VimInsertNormal.

    . ., 1

    , , , , .

    .

    "?config""config". , .

    , 2

    1: , , . . :-).2: CTRL-W c, Vim

    , , CTRL-C, , , , :q

    169

  • 8/14/2019 vim user manual 70

    170/438

    170 20

    : |usr 21.txt| Go away and come back : |manual-copyright| vim:tw=78:ts=8:ft=help:norl:

    170

  • 8/14/2019 vim user manual 70

    171/438

    171 21

    *usr 21.txt* Vim 7.0.: 20060425

    VIM--- : Bram Moolenaar

    ---

    Vim. Vim

    , Vim. , Vim

    , .

    |21.1| |21.2| shell|21.3| : viminfo|21.4| |21.5| |21.6|

    : |usr 22.txt|

    : |usr 20.txt| : |usr toc.txt|

    *21.1*

    UnixVimCTRL-Z. VimVimshell. . "fg"

    Vim.

    shell commandCTRL-Z

    {shell}fg

    , .

    CTRL-Z, ":suspend".

    Vim, .

    171

  • 8/14/2019 vim user manual 70

    172/438

    172 21

    Unix. Vimshell.shell, shell,Vim1.

    GUIVimVimshell. CTRL-Z

    2

    *21.2* shell

    shellVim":!{command}"., :

    ex command:!ls

    :!dir

    Unix, MS-Windows.

    Vim. .

    .

    "!". :

    ex command:!{program} {program}

    :r !{program} {program}

    :w !{program} {program}

    :[range]!{program} {program}

    3"!{program}". , .

    , shell.shell:

    ex command:shell

    1: , shell,

    2: windowsgvim, CTRL-Zu, , :unmap , CTRL-Z

    3: , , ?

    172

  • 8/14/2019 vim user manual 70

    173/438

    173 21

    CTRL-ZVim. shell.

    GUIVimshellVim. Vim

    . . ,'guipty'. ,

    shell. :

    ex command:!xterm&

    *21.3* : viminfo

    ,

    , . Vim. !

    viminfo:

    List

    Vimviminfo. Vim.

    'viminfo'.

    . :

    ex command:set viminfo=string

    string.

    . /.

    viminfostring. '(a-z).

    (1000). :

    ex command:set viminfo='1000

    173

  • 8/14/2019 vim user manual 70

    174/438

    174 21

    f(A-Z0-9). 0

    . 1f, . :

    ex command:set viminfo='1000,f1

  • 8/14/2019 vim user manual 70

    175/438

    175 21

    VIMviminfo

    Vim":wviminfo"":rviminfo"

    . Vim, ,Vim :

    ex command:wviminfo! ~/tmp/viminfo

    :

    ex command:rviminfo! ~/tmp/viminfo

    , "w""write", "r""read".

    ":wviminfo"!viminfo. viminfo.

    ":rviminfo"!viminfo

    , 1.

    info. viminfo, .

    *21.4* 2

    Vim. .

    , .

    Vim3., , , . ('sessionoptions', )

    :

    ex command:mksession vimbook.vim

    , :

    ex command:source vimbook.vim

    1: : !2: viminfo3: ,

    175

  • 8/14/2019 vim user manual 70

    176/438

    176 21

    Vim, :

    shell commandvim -S vimbook.vim

    Vim. 'S'session(, -SVim. "source").

    , , . .

    'sessionoptions'.

    "blank,buffers,curdir,folds,help,options,winsize".

    Listblank

    buffers ,

    curdir

    folds folds,

    help

    options

    winsize

    . Vim, :

    ex command:set sessionoptions+=resize

    ,

    .

    "~/.vim" . "screen", "boring":

    ex command:wall

    :mksession! ~/.vim/secret.vim:source ~/.vim/boring.vim

    ":wall". ":mksession!". . "secret"

    . "boring".

    , , , ,

    :

    176

  • 8/14/2019 vim user manual 70

    177/438

    177 21

    ex command:source ~/.vim/boring.vim

    ,

    ,

    .

    , . , :

    Display+----------------------------------------+

    | VIM - main help file |

    | |

    |Move around: Use the cursor keys, or "h|

    |help.txt================================|

    |explorer | |

    |dir |~ |

    |dir |~ |

    |file |~ |

    |file |~ |

    |file |~ |

    |file |~ |

    |~/=========|[No File]===================|

    | |

    +----------------------------------------+

    , . . plugin.

    . .

    Vim:

    ex command:help

    CTRL-W w

    :vertical split ~/

    . :

    ex command:mksession ~/.vim/mine.vim

    Vim:

    ex commandvim -S ~/.vim/mine.vim

    177

  • 8/14/2019 vim user manual 70

    178/438

    178 21

    : ,

    "O", .

    UNIXMS-WINDOWS

    MS-WindowsUnix. ,

    "slash""unix"'sessionoptions'. . :

    ex command:set sessionoptions+=unix,slash

    Vim Unix , MS-Windows Vim Unix .UnixVimMS-Windows. , MS-WindowsVim/, UnixVim\.

    VIMINFO

    , , .viminfo.

    viminfo.

    . , .

    viminfo. . :

    ex command:mksession! ~/.vim/secret.vim

    :wviminfo! ~/.vim/secret.viminfo

    :

    ex command:source ~/.vim/secret.vim

    :rviminfo! ~/.vim/secret.viminfo

    *21.5*

    Vim .

    , .

    : . 'number', folds. ,

    . , .

    178

  • 8/14/2019 vim user manual 70

    179/438

  • 8/14/2019 vim user manual 70

    180/438

    180 21

    :

    ex com