Your SlideShare is downloading. ×
vim手册
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

vim手册

2,353
views

Published on

简单的vim工具的手册

简单的vim工具的手册

Published in: Automotive, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,353
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 1 __ ___ ___ ____ ____ | | / / / / / | / | | || / / / /__/ / / || / || | || / / / __/ / /| || / /| || | || / / / ___ / / | || / / | || | || / / / / / / / /| || / / /| || | || / / / / / / / / / | ||/ / / | || | || / / / / / / / / / | |/ / / | || | || / / / / / / / / / | / / | || | || / / / / / / / / / | / / | || | ||/ / / / / / / / / | / / | || | |/ / / / / / / / / |__/ / | || | / / / / / / / / __/ | || | / / / / / / / / | || | / / / / / / / / | || |__/ / /__/ / /__/ / |__|| __/ __/ __/ __| Bram Moolenaar ZhaoRuFei<slimzhao@hotmail.com> 7.2 1
  • 2. 2 Vim Vim Vim Vim Vim Vim Vim 1 Vim notepad, word, edit Vim BUG Vim( vi) Vim Vim 1 Emacs 2
  • 3. 3 Vim notepad, edit UNIX :help xxx Mission Impossible Vim 1 i18n internationalization Vim the teh Vim script Vim Vim Vim SHELL Vim Vim Vim Vim LTEX A LTEX A email <slimzhao@hotmail.com> 1 " " " " 3
  • 4. 4 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 <slimzhao@hotmail.com> 2004/06/08 4
  • 5. 5 Acrobat Reader 5
  • 6. 6 0.2 0.20.2 0.1 2 ( ). Acrobat AcrobatReader 5 6 3 4============================== % (<qzhen@flotu.org>) gbk2uni.exe CTex 6
  • 7. 7 6.3.0 6.3.01. 6.3.0 VIM 6.3, 6.12. 6.3.0 0.2(A) 0.1 0.2 usr 21.txt, usr 22.txt, usr 29.txt, usr 45.txt 4 4(B) shell ex command :au BufRead *.tip setf tip 7 Vim ex command 6 normal mode command Vim normal normal mode command gg=G shell command unix shell windows OS DOS BOX shell command env LANG=de_DE.ISO_8859-1 vim Display 7
  • 8. 8 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 List r Insert o Normal "o" "O" c textwidth code code while i < b { if a { b = c; } } url URL http://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz (C) cmtt computer modern typewriter cmr(computer modern roman) Latex L TEX A cmr cmtt LTEX A A 1 1 <unicell@gmail.com> " " " " " ; " 8
  • 9. 9 6.3.0(D) URL email mail(E) ‘‘...’’(LTEX A ), ... "..." ’ /hello hi hi(F) CTRL-N, <Esc>(G) BUG 1 / ...(H) PDF HTML HTML bgcolor PDF PDF Tex 2 PL (Public License Piao Liang) windows3. TODO: upquote LTEX package A ’ fancyvrb " " " " . 1 " " " " . 2 PDF 9
  • 10. 10 6.3.0 --- LTEX A TMD 10
  • 11. 11 7.0 7.00. 7.0 " " Bram Beta 7.0fBeta 7.0 " " 7.0 release 7.01. List- 50- :Omni--- Vim ( Python )- Vim- Unicode--- grep- zip/tar---- http://groups.yahoo.com/group/vimannounce/message/1592. , , VIM :colorscheme default, |41.1| | , . | .3. , , , . 11
  • 12. 12 7.1 7.1 7.1 7.0 bugfix bugfix shell command cd $VIM/vim71/doc for i in usr*; do diff ../../vim70/doc/$i $i; done > tmp.txt wc tmp.txt 366 Display1c1< *usr_01.txt* For Vim version 7.1. Last change: 2006 Oct 08---> *usr_01.txt* For Vim version 7.0. Last change: 2006 Apr 24 132 (A) |02.8| ( ) (B) |10.2| ":substitute" p p (C) |12.1| "fourty" "fourteen" fourty (D) |24.3| Omni (E) |41.10| Comments Unix Vim Vim shell 12
  • 13. 13 7.1 1. 1.5 2. LTEX A LTEX A LTEX A 3. Mail " ... " " ... " 11,300,000 23,600,000 google :-) " " " " 1986 " " " " " ... " " ... " <step by step@263.net> Mail 13
  • 14. 14 7.1 :-) LTEX A 14
  • 15. 15 7.2 7.27.2 7.2 7.1 7.1 7.0 bugfix 7.2 | 7.1 | 15
  • 16. 16 LTEX A LTEX A0. LTEX A <slimzhao@hotmail.com> LTEX A *1*. fancyvrb Verbatim a ba 7.1b 7.12*. fancyvrb Verbatim Verbatim xleftmargin xrightmargin 16
  • 17. 17 LTEX A3*. CJK " " "s:count" "other.vim" 1 COPY sloppy LTEX A / "s:count" "other.vim"4*. : EMAIL slimzhao@21cn.com " a" CopyRight c LTEX A marvosym MVAt @ MAIL : L TEX Anewcommand{VimMailURL}[1] {textcolor{VimURLColor}{href{mailto:#1}{#1}} email VimMailURL #1 @ MVAt. 1 Vim C/C++/Java "[a-zA-Z ][a-zA-Z0-9 ]*" 17
  • 18. 18 LTEX A L TEX Anewcommand{VimMailURL}[2]{ texttt{<}textcolor{VimURLColor}{href{mailto:#1@#2} {#1{footnotesizeMVAt}#2}}texttt{>}} Vim VimMailURL{xxx}{yyy.zzz}5. LTEX A 6.3 18
  • 19. 19 LaTeX LTEX A LTEX A <rice maxwell@163.com> <chunmin.yang@gmail.com> LTEX A TEX/LTEX A PDF LTEX A LTEX A PDF TEX LTEX A LTEX A .zip CTeX 19
  • 20. 200. <002424@fudan.edu.cn> PDF AcrobatReader Acrobat 7 -> ( CTRL-K) check box RGB (255,255,242).1. <laneast@hotmail.com> HTML Txt HTML LTEX A docbook2. <chunmin.yang@gmail.com> Vim3. <chenbo.liu@gmail.com> PDF j k Acrobat Reader4. (<taker2001@gmail.com>,<chunlinyao@gmail.com>, <chunmin.yang@gmail.com> ) Vim Vim 90% 90% bash : 20
  • 21. 21 shell commandfor i in usr*; do diff ../../vim70c/doc/$i $i; done > tmp.txtgvim tmp.txt & 7.05. MAIL :<002424@fudan.edu.cn><ankyhe@gmail.com><baikaishiuc@hotmail.com><chenbo.liu@gmail.com><chunlinyao@gmail.com><chunmin.yang@gmail.com><huanlf@gmail.com><KDV367@motorola.com><laneast@hotmail.com><livahu@gmail.com><lsl635@sina.com><maintainer@vim.org><rice maxwell@163.com><ringken@gmail.com><step by step@263.net><taker2001@gmail.com><unicell@gmail.com><xyzguy@126.com><yangxcmail-linux@yahoo.com.cn><zhasm64@gmail.com> sort -f| uniq -i mail6. MAIL 21
  • 22. 22 00*usr toc.txt* Vim 7.0 . 2006 04 24 VIM --- Bram Moolenaar <slimzhao@hotmail.com> *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| 22
  • 23. 23 00|usr 23.txt||usr 24.txt||usr 25.txt||usr 26.txt||usr 27.txt||usr 28.txt||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| HTML PDF http://vimdoc.sf.net 23
  • 24. 24 00 Vim|usr 01.txt| |01.1| |01.2| |01.3| Vim |01.4||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| 24
  • 25. 25 00|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| |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| 25
  • 26. 26 00 |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||usr 10.txt| |10.1| |10.2| |10.3| |10.4| |10.5| |10.6| |10.7| |10.8| |10.9| 26
  • 27. 27 00|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| 1 |12.6| |12.7| |12.8| word|usr 20.txt| |20.1| |20.2| |20.3| |20.4| |20.5||usr 21.txt| 1 Unix 27
  • 28. 28 00 |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 28
  • 29. 29 00|usr 25.txt| 1 |25.1| |25.2| |25.3| |25.4| |25.5||usr 26.txt| |26.1| Visual |26.2| |26.3| |26.4| shell Vim|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| 1 <unicell@gmail.com> ! 29
  • 30. 30 00 |28.5| |28.6| |28.7| |28.8| |28.9| |28.10| ?|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| 30
  • 31. 31 00 |32.1| |32.2| |32.3| Vim Vim|usr 40.txt| |40.1| |40.2| |40.3||usr 41.txt| Vim |41.1| |41.2| |41.3| |41.4| |41.5| |41.6| |41.7| |41.8| |41.9| |41.10| |41.11| plugin |41.12| plugin |41.13| plugin |41.14| plugin |41.15| |41.16| Vim|usr 42.txt| 31
  • 32. 32 00 |42.1| |42.2| |42.3| |42.4||usr 43.txt| |43.1| |43.2||usr 44.txt| |44.1| |44.2| |44.3| |44.4| |44.5| |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| 32
  • 33. 33 00 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: 33
  • 34. 34 01*usr 01.txt* Vim 7.0 . 2008 05 07 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 : 1 Vim HTML <ahref=#somewhere>click here</a> click here "click here" Vim CTRL-] CTRL-] 34
  • 35. 35 01 ListCTRL-]CTRL-O |bars| number, ":write" CTRL-] CTRL-] ":help" |help.txt|.*01.2* Vim ( GUI ) |usr 90.txt| *not-compatible* Vi Vim Vi vimrc VIM Unix: ex command:!cp -i $VIMRUNTIME/vimrc_example.vim ~/.vimrcMS-DOS, MS-Windows, OS/2: ex command:!copy $VIMRUNTIME/vimrc_example.vim $VIM/_vimrcAmiga: ex command:!copy $VIMRUNTIME/vimrc_example.vim $VIM/.vimrc Vim, compatible 35
  • 36. 36 01 ex command:set compatible? nocompatible "compatible" ex command:scriptnames compatible |vimrc| |compatible-default| : Vim "evim"(easy vim) Vim Notepad Insert |evim-keys|*01.3* Vim ( !) vimtutor Vim 30 Unix Vim shell commandvimtutor MS-Windows " /Vim" $VIMRUNTIME vimtutor.bat. 36
  • 37. 37 01 shell commandvimtutor fr Unix , Vim, "gvimtutor" "vimtutor -g" "vimtutor". OpenVMS VIM shell command@ VIM:vimtutor 1. VIM ( ): shell commandvim -u NONE -c e $VIMRUNTIME/tutor/tutor -c w! TUTORCOPY -c q "TUTORCOPY" shell commandvim -u NONE -c e $VIMRUNTIME/tutor/tutor.fr -c w! TUTORCOPY -c q2. Vim shell commandvim -u NONE -c "set nocp" TUTORCOPY Vim happy 3. shell commanddel TUTORCOPY*01.4* *manual-copyright* 37
  • 38. 38 01 Vim c 1988-2003 by BramMoolenaar " "1.0 http://www.opencontent.org/opl.shtml *frombook* Steve Oualline Vi IMproved - Vim ( New Riders ISBN:0735710015). " " ( Vim 6.0 ) |frombook| Steve Oualline New Riders OPL |iccf| |usr 02.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 38
  • 39. 39 02 Vim*usr 02.txt* Vim 7.0 . 2007 02 28 VIM --- Bram Moolenaar Vim 1 --- << >> 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 1 39
  • 40. 40 02 Vim Vim. UNIX Microsoft Windows, MS-DOS Vim file.txt Display+---------------------------------------+|# ||~ ||~ ||~ ||~ ||"file.txt" [New file] |+---------------------------------------+("#" .) (~) Vim file.txtVIM gvim shell commandvim file.txt xterm xterm MicrosoftWindows MS-DOS gvim*02.2* Vim Normal Insert Normal 40
  • 41. 41 02 Vim Insert Vim Normal Insert "i" (i Insert) DisplayiA very intelligent turtleFound programming UNIX a hurdle"turtle" <Esc> Insert Normal Vim Display+---------------------------------------+|A very intelligent turtle ||Found programming UNIX a hurdle ||~ ||~ || |+---------------------------------------+ ex command:set showmode ( ) ( ). "i" Vim --INSERT-- Insert 41
  • 42. 42 02 Vim Display+---------------------------------------+|A very intelligent turtle ||Found programming UNIX a hurdle ||~ ||~ ||-- INSERT -- |+---------------------------------------+ <Esc> Normal 1 "--INSERT--" Vim --- <Esc> Normal ( Normal ) <Esc> Vim 2 Normal*02.3* Normal Listhjkl l right ( ) 1 Normal --NORMAL-- 2 google 42
  • 43. 43 02 Vim : hjkl h l j k h l j "i" Insert hjkl <Esc> Normal |vimtutor| Hiroshi Iwatani Display Komsomolsk ^ | Huan Ho <--- ---> Los Angeles(Yellow river) | v Java (the island, not the programming language)*02.4* "x". ( xxxx ) xxxxxxx(7 x) "A very " 43
  • 44. 44 02 Vim Display+---------------------------------------+|intelligent turtle ||Found programming UNIX a hurdle ||~ ||~ || |+---------------------------------------+ DisplayiA young <Esc> i( Insert ) "A young" Insert ( <Esc>) Display+---------------------------------------+|A young intelligent turtle ||Found programming UNIX a hurdle ||~ ||~ || |+---------------------------------------+ "dd" Display+---------------------------------------+|Found programming UNIX a hurdle ||~ ||~ ||~ || |+---------------------------------------+ Vim "J" 44
  • 45. 45 02 Vim DisplayA young intelligentturtle "J": DisplayA young intelligent turtle*02.5* "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 ... 45
  • 46. 46 02 Vim Displayung intelligent turtleoung intelligent turtleyoung intelligent turtle young intelligent turtleA young intelligent turtle : "u" Vim Vi |not-compatible| Vim Vim Vi CTRL-R( ) CTRL-R A Displayyoung intelligent turtle "U" "U" DisplayA very intelligent turtle xxxx veryA intelligent turtle xxxxxx turtleA intelligent "U"A very intelligent turtle "u" "U"A intelligent "U" "u" CTRL-R 46
  • 47. 47 02 Vim "u" CTRL-R |32.1|*02.6* Vim |Q in| "i" "a" "i" Displayand thats not saying much for the turtle. Displayand thats not saying much for the turtle!!! "x" turtle e normal mode commanda!!!<Esc> e Displayand thats not saying much for the turtle!!! "o" Insert DisplayA very intelligent turtleFound programming UNIX a hurdle 47
  • 48. 48 02 Vim "o" normal mode commandoThat liked using Vim<Esc> DisplayA very intelligent turtleThat liked using VimFound programming UNIX a hurdle"O" ( O) 9 "kkkkkkkkk" "9k" "a!!!<Esc>" "3a!<Esc>" 3 3 3 "3x"*02.7* Vim "ZZ" Vim. : Vim "ZZ", Vim Vim |07.4| Vim ex command:q! 48
  • 49. 49 02 Vim 3 (:) q 1 2 (.!) Vim ":q" Vim DisplayE37: No write since last change (use ! to override) Vim, " ". ":e!"*02.8* Vim ex command:help <F1> <F1> ":help" Vim ( ) hljk "ZZ" Vim. ( |help|) 1 Vim 2 :! w! 49
  • 50. 50 02 Vim CTRL-]( ) ( Vim CTRL-] word 1 CTRL-T( ) CTRL-O( ) *help.txt* "*" ( ). |29.1| 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 1 HTML HTML<a href="http://www.w3.org/2001/HTML">HTML</a> Vim tag Vim 50
  • 51. 51 02 Vim 1Vim Normal Normal CTRL-H ex command:help CTRL-H Insert "i " CTRL-H ex command:help i_CTRL-H Vim - -t ex command:help -tVim number ex command:help number |help-context| Insert ex command:help i_<Up> DisplayE37: No write since last change (use ! to override) ID 1 Insert Normal 51
  • 52. 52 02 Vim ex command:help E37 ex command :help ( Vim ). ex command :help usr_toc.txt 1 ex command :help :subject "subject" ex command :help :help ex command :help abc normal "abc" ex command :help CTRL-B normal <C-B> ex command :help i_abc :help i_CTRL-B 1 7.1 user-toc.txt 52
  • 53. 53 02 Vim ex command :help v_abc :help v_CTRL-B Visual ex command :help c_abc :help c_CTRL-B ex command :help ’subject’ subject ex command :help subject() "subject" ex command :help -subject 1 "-subject" ex command :help +subject "+subject" ex command :help EventName "EventName" 1 " " shell vim Vim 53
  • 54. 54 02 Vim ex command :help digraphs.txt "digraphs.txt" ex command :help pattern<Tab> "pattern" <Tab> ex command :help pattern<Ctrl-D> "pattern" ex command :helpgrep pattern "pattern" ex command :cn ex command :cprev :cN ex command :cfirst :clast / 54
  • 55. 55 02 Vim ex command :copen :cclose / <Enter> |usr 03.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 55
  • 56. 56 03*usr 03.txt* Vim 7.0 . 2006 06 21 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" 3 words 56
  • 57. 57 03 DisplayThis is a line with example text --->-->->-----------------> w w w 3w word "w" word "b"1 word Display This is a line with example text <----<--<-<---------<--- b b b 2b b "e"2 word 3 . "w" "b" "e" "ge" 4 word : DisplayThis is a line with example text <- <--- -----> ----> ge ge e e word "w" word "w" "l" "b" non-word ".", "-" ")" word Vim word iskeyword WORDs WORD word WORD word 1 backward 2 :end of word 3 "w" word "e" word 4 "e" word word 57
  • 58. 58 03 Display ge b w e <- <- ---> --->This is-a line, with special/separated/words (and some more). <----- <----- --------------------> -----> gE B W E*03.2* "$" <End> 1 "^" . "0" <Home> Display ^ <------------.....This is a line with example text<----------------- ---------------> 0 $("....." ) "$" "1$" "2$" "0" "0" "0" 2 "^"*03.3* 1 2 "^" 58
  • 59. 59 03 "fx" x "f" "find" human h "fh" DisplayTo err is human. To really foul up you need a computer.---------->---------------> fh fy "fy" really "3fl" "foul" "l" DisplayTo err is human. To really foul up you need a computer. ---------------------> 3fl 1"F" : DisplayTo err is human. To really foul up you need a computer. <--------------------- Fh"tx" "fx" "t" "To" "Tx": DisplayTo err is human. To really foul up you need a computer. <------------ -------------> Th tn 4 ";" "," 2 4 1 : 2 "Fx" "," 59
  • 60. 60 03 1*03.4* () %2 "(" ")" 3 ")" "(" : Display % <----->if (a == (b * c) / d) <----------------> % [] {} ( 4 matchpairs ) "%" "%" "(", ")": codeif (a == (b * c) / d)---+----------------> %*03.5* C C++ 1 "fx" x "f" Vim Windows 2 (<qzhen@flotu.org>) 3 4 <> HTML, XML 60
  • 61. 61 03 Displayprog.c:33: j undeclared (first use in this function) 33 33 "9999k"1 "32j" 32 2 "G" "33G" 33 (|usr 30.txt| :make ) 3 , "G" "gg" "1G" Display | first line of a file ^ | text text text text | | text text text text | gg7G | 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 4 "%" . 5 "50%" . "90%" 6 1 9999 C/C++ Vim 2 G Go 3 Vim 4 : N 5 50% 6 Vim :goto 3 61
  • 62. 62 03 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. 1 2. number ex command:set number 1 62
  • 63. 63 03 1 2 : ex command:set nonumber number "no" Vim 3. ruler Vim ex command:set ruler ruler 3*03.7* CTRL-U CTRL-D 1 " " <xyzguy@126.com> 2 :no boolean 3 Vim set number :set nonumber ruler number |gq| 63
  • 64. 64 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 1 2 CTRL-B CTRL-F CTRL-B "j" "zz" 1 Forward 2 Backward 64
  • 65. 65 03 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 |+------------------+ +------------------+ 1 2"zt" "zb" |Q sc| scrolloff*03.8* "/string" "include" normal mode command/include 3 "/" Vim : .*[]^%/?~$ "n" #include: 1 "zt" t top z zt Zhuan Tie( ) :-) 2 "b" bottom 3 Vim 65
  • 66. 66 03 normal mode command/#include "n" #include "n" "3n" 3 "/" 1 2 "?" "/" : normal mode command?word"N" "/" "?" "/" "N" "?" "N" ignorecase ex command:set ignorecase "word" "Word" "WORD" ex command:set noignorecase 1 normal / N N / /text n N / N :a 1 ba 2 ba 3 ba 4 ba 5 ba 6 b normal 1 2/d 3 2 n 4 2 Vim 66
  • 67. 67 03 3 normal mode command/one/two/three "/" Vim "/three" "three" Vim "/two" "/one" "/o<Up>"1 Vim "/one" ":" WORD word "TheLongFunctionName" "/TheLongFunctionName" Vim word "*" Vim word 2 "#" "*" :"3*" word WORD "/the" Vim "there" "the" 1 <Up> 2 : word ? Visual select, yank, :let @ /=@", n 67
  • 68. 68 03 normal mode command/the>">"1 word "<" 2 word word "the" normal mode command/<the> "there" "soothe". "*" "#" word word( "g*" "g#" word .) "nr" "nr" "*" "n" ex command:set hlsearch "nr", Vim 3 ex command:set nohlsearch 4 : ex command:nohlsearch 1 <qujianning@gmail.com> > 2 word 0 3 |/%<3l| 4 hlsearch 68
  • 69. 69 03 hlsearch "n" "N" ex command:set incsearch Vim ex command:set nowrapscan wrapscan 1 Vim Vim |not-compatible| ex command:scriptnames ex command:edit ~/.vimrc Vim ex commandGo:set hlsearch<Esc> 1 <qujianning@gmail.com> INTERMEZZO 69
  • 70. 70 03"G" "o" ":set" <Esc> normal mode commandZZ Vim hlsearch*03.9* Vim |usr 27.txt|. |pattern| ^ 1 6 "include" include "^include" include. $ "was$" was. "x" "the" Displaythe solder holding one of the chips melted and thexxx xxx xxx "/the$" Displaythe solder holding one of the chips melted and the xxx "^the" 1 70
  • 71. 71 03 Displaythe solder holding one of the chips melted and thexxx "/^the$" "the" "the " . "c.m" 1 c m DisplayWe 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`` 1 l 71
  • 72. 72 03 1 ` ` "/" "n" ( ) "fx" "tx" word "w" "e" "j" "k" `` CTRL-O ( O older). CTRL-I ( I O ) 3 normal mode command33G/^TheCTRL-O 2 33 "The" CTRL-O 33 CTRL-O "33G" CTRL-I 33 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 1 ` 1 2 " " 72
  • 73. 73 03 : CTRL-I <Tab> ":jumps" ">" Vim "ma" "a" a z 26 Vim `{mark}, {mark} normal mode command`a mark( ) mark `mark `mark mark s(start) normal mode commandms e(end) normal mode commandme normal mode commands e e 73
  • 74. 74 03 1 2 s e ex command:marks List"[] |usr 04.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 1 start 2 end 74
  • 75. 75 04*usr 04.txt* Vim 7.0 . 2006 06 21 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| 1 |usr 05.txt| Vim |usr 03.txt| |usr toc.txt|*04.1* 2 "x" "4x" 4 "dw" word "w" word "d" 75
  • 76. 76 04 "4w" 4 word "d4w" 4 word. DisplayTo err is human. To really foul up you need a computer. ------------------> d4wTo err is human. you need a computer. Vim Vim word "e" word 1 Vim : DisplayTo err is human. you need a computer. --------> d2eTo err is human. a computer. " " 2 " " "$" "d$" " " DisplayTo err is human. a computer. ------------> d$To err is human + "d" "4l" "w" 1 2 exclusive inclusive [0, 5) 0≤x<5 [0, 5] 0≤x≤5 . 76
  • 77. 77 04*04.2* "c" "d" Insert "cw" word word Insert DisplayTo err is human -------> c2wbe<Esc>To be human "c2wbe<Esc>" Listc2w word( Insert )be<Esc> Normal "human" "cw" "c" d :"cw", "ce" word word Vi Vim 1 "dd" "cc" ( ). "d$" "c$" "d$" "a" Insert 1 : 77
  • 78. 78 04 + Listx dl( )X dh( )D d$( )C c$( )s cl( )S cc( ) "3dw" "d3w" 3 word "3dw" word 3 "d3w" 3 word "3d2w" word 3 6 word. "r" "cl" "s" "r" <Esc> Normal Displaythere is somerhing grong hererT rt rwThere is something wrong here "r" DisplayThere is something wrong here 5rxThere is something xxxxx here 78
  • 79. 79 04 "r<Enter>" 1 "4r<Enter>" 4*04.3* "." Vim HTML <B> <B> < "df>" </B> < "." "." ( "df>") < "." Display To <B>generate</B> a table of <B>contentsf< < --->df> > -->f< < --------->. df> --->f< < ------------->. df> --> "." "u" CTRL-R ( "." Normal Displayasdf 123asdf 1234 1 "cwxyz" Normal Displayasdf xyz 1 Displayasdf xyz 1 79
  • 80. 80 04 Displayasdf xyz4 3 xyz.) "four" "five" List/four<Enter> "four"cwfive<Esc> "five"n "four". "five"n.*04.4* Visual + Visual "v" Visual DisplayThis is an examination sample of visual mode ----------> velllldThis is an example of visual mode "l" "d" <Esc> Visual 80
  • 81. 81 04 "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-V Visual Displayname Q1 Q2 Q3pierre 123 455 234john 0 90 39steve 392 63 334 "Q2" "Q2" "Q" CTRL-V Visual "3j" 3 "w" word "h" "d" Visual "o" ( o other end ) "o" 4 "o" "O" 81
  • 82. 82 04 1 "o" "O" Visual Normal Normal*04.5* "d" "x" p ( Vim put) "dd" "p" Displaya line a line a lineline 2 dd line 3 p line 3line 3 line 2 "p" ( word), 2"p" DisplaySome more boring try text to out commands. ----> dwSome more boring text to out commands. --------> welpSome more boring text to try out commands. PUTTING "P" "p" 1 4 2 82
  • 83. 83 04 "dd" "P" 1 "dw" "P" "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" 3 "p" Yanking Vim "c" 4 , "y" "yank" "y" "y" "yw" word. "y2w" word: 1 2 term:yanking 3 " " (") 4 change copy 83
  • 84. 84 04 Displaylet sqr = LongVariable * --------------> y2wlet sqr = LongVariable * plet sqr = LongVariable * LongVariable "yw" word "ye" "yy" "dd" "D" "Y" "y$" Displaya text line yy a text line a text lineline 2 line 2 p line 2last line last line a text line last line*04.7* Vim GUI (gvim) "Edit" "Copy" Visual Edit/Copy 1 Vim . Vim Edit/Paste Normal Insert Visual 1 Copy Normal yank Copy Vim *, y Vim " Vim 84
  • 85. 85 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. dawthis is some text. "daw" "d" "aw" "aw" "A Word" "daw" "Delete A Word" Word ( ). 1 Vim Perl There is more than one way to do the samething. <huanlf@gmail.com> PERL Perl Perl perl : perl Perl PERL Perl 85
  • 86. 86 04 Vim + Visual + + "cis" DisplayHello there. Thisis an example. Justsome text. "is an" "cis" DisplayHello there. Justsome text. "Another line.": DisplayHello there. Another line. Justsome text. "cis" "c" "is" "Inner Sentence" "as"(a sentence) "das". "cis" Visual Visual Visual "v" Visual "as" "as" |text-objects|*04.9* 86
  • 87. 87 04 "R" Vim replace 1 <Esc> . "text" "t" Replace DisplayThis is text. Rinteresting.<Esc>This is interesting. 12 "interesting." 2 5 "text." "R" <Insert> Insert Replace 3 <BS>*04.10* N M N*M |operator| 1 replace 2 12 <ringken@gmail.com> . 3 Replace 87
  • 88. 88 04 Listx ("dl" )X ("dh" )D ("d$" )dw worddb worddiw word( )daw word( )dGdgg "c" "d" "y" yank List~ ( tildeopa VisualI InsertA Inserta tildeop g~ |usr 05.txt| Vim |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 88
  • 89. 89 05 Vim*usr 05.txt* Vim 7.0 . 2007 05 11 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 ( ) : 89
  • 90. 90 05 Vim ex command:$MYVIMRC vimrc |vimrc| ":version" Vim Unix Macintosh -- List~/.vimrc MS-DOS MS-Windows List$HOME/_vimrc$VIM/_vimrc vimrc Vim incsearch vimrc ex commandset incsearch Vim Vim vim |usr 41.txt|*05.2* vimrc *vimrc example.vim* vimrc ( Vim ) Vim not-compatible ( |not-compatible|) List$VIMRUNTIME/vimrc_example.vim 90
  • 91. 91 05 Vim ":help" ex commandset nocompatible Vim Vi compatible ex commandset backspace=indent,eol,start Vim Insert Vim Insert ex commandset autoindent Vim Insert Normal o ex commandif has("vms") set nobackupelse set backupendif Vim VMS "~" |07.4| ex commandset history=50 91
  • 92. 92 05 Vim ex commandset ruler Vim ex commandset showcmd Vim "2f", Vim "2f" "w" "2fw" Vim "2f" Display+-------------------------------------------------+|text in the Vim window ||~ ||~ ||-- VISUAL -- 2f 43,8 17% |+-------------------------------------------------+ ^^^^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^ showmode showcmd rulerset incsearch 1 .. ex commandmap Q gq "Q" "gq" Vim5.0 "Q" "Q" Ex 1 : 92
  • 93. 93 05 Vim ex commandvnoremap _g y:exe "grep /" . escape(@", ’/’) . "/ *.c *.h"<CR> Visual C ex commandif &t_Co > 2 || has("gui_running") syntax on set hlsearchendif hlsearch Vim "if" Vim |usr 41.txt| *vimrc-filetype* ex commandfiletype plugin indent on Vim 1. Vim "main.c", Vim ".c" "c" C "#!/bin/sh" Vim "sh" shell 2. plugin 1 "c" cindent Vim plugin |write-filetype-plain| 1 93
  • 94. 94 05 Vim 3. Vim |filetype-indent-on| indentexpr ex commandautocmd FileType text setlocal textwidth=78 Vim 78 "autocmd FileType text" "text" "setlocal textwidth=78" "textwidth" 78 ex commandautocmd BufReadPost * if line(""") > 0 && line(""") <= line("$") | exe "normal g‘"" | endif "1 |line-continuation| Vim*05.3* Vim "amount" "{amount}" ":map" Vim F5 ex command:map <F5> i{<Esc>ea}<Esc> 1 94
  • 95. 95 05 Vim : 4 <F5> 5 <Esc> F5 ESC <F5> F5 i{<Esc> { <Esc> Insert e word a}<Esc> word } word word F5. Vim 1 Vim "p" word "c" ex command:map p i(<Esc>ea)<Esc>:map c i{<Esc>ea}<Esc>2 p 3 Vim ":map" ( ) Normal |40.1|*05.4* plugin *add-plugin* *plugin* Vim plugin plugin 1 2 <qujianning@gmail.com> p=>p 3 |timeoutlen| 95
  • 96. 96 05 Vim Vim plugin plugin plugin plugin|add-filetype-plugin| plugin *standard-plugin* Vim plugin plugin Vim Vim |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|. plugins vimball |vimball| plugins |getscript| 96
  • 97. 97 05 Vim plugin plugin copy plugin List pluginUnix ~/.vim/plugin/PC and OS/2 $HOME/vimfiles/plugin or $VIM/vimfiles/pluginAmiga s:vimfiles/pluginMacintosh $VIM:vimfiles:pluginMac OS X ~/.vim/plugin/RISC-OS Choices:vimfiles.plugin Unix ( plugin ): shell commandmkdir ~/.vimmkdir ~/.vim/plugincp /usr/local/share/vim/vim60/macros/justify.vim ~/.vim/plugin plugin plugins plugin/ plugin/ " /.vim/plugin/perl/*.vim" Perl plugins. plugin *add-filetype-plugin* 1*ftplugins* Vim plugin ex command:filetype plugin on |vimrc-filetype| plugin plugin: 1 97
  • 98. 98 05 Vim 1. plugin. 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 commandmv thefile ~/.vim/ftplugin/stuff_too.vim "otherstuff.vim" Vim "otherstuff" MS-DOS plugin 1 6 shell commandmkdir $VIM/vimfiles/ftplugin/fortrancopy thefile $VIM/vimfiles/ftplugin/fortran/too.vim 1 MS-DOS 8 6 plugin 98
  • 99. 99 05 Vim plugin Listftplugin/<filetype>.vimftplugin/<filetype>_<name>.vimftplugin/<filetype>/<name>.vim "<name>" Unix "stuff" List~/.vim/ftplugin/stuff.vim~/.vim/ftplugin/stuff_def.vim~/.vim/ftplugin/stuff/header.vim <filetype> plugin plugin. plugin <name> Vim plugin <name> ".vim" List|filetype-plugins| plugin|load-plugins| Vim plugin|ftplugin-overrule| plugin|write-plugin| plugin|plugin-details| plugin plugin bug.|new-filetype|*05.5* *add-local-help* *matchit-install* plugin plugin "matchit.vim" plugin ( Vim ). plugin "%" HTML Vim 99
  • 100. 100 05 Vim if/else/endif Vim ( ). plugin "matchit.txt" plugin Vim 1 $VIMRUNTIME . ( 2 "mkdir" ). 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/doc3 4 |:helptags| tags . 1 MS-DOS MS-Windows 2 MS-DOS MS-Windows mkdir md mkdir MS-DOS, MS-Windows Unix Mac OS X( Darwin Unix ) 3 <qujianning@gmail.com> $=>$ 4 tags / C/C++/Java foo tags tags-aware Vim/Emacs tags tags + + tags man ctags, man etags 100
  • 101. 101 05 Vim ex command:helptags ~/.vim/doc ex command:help g% "g%" ex command:help local-additions |write-local-help|*05.6* |options| ex command:options CTRL-O "displayingtext" ex commandset wrap nowrap 101
  • 102. 102 05 Vim ex commandset nowrap wrap wrap 1 wrap 2 ex commandset so=0 "$" 0 "r5" 5 scrolloff*05.7* Vim ":help" 3 ex command:help wrap & ex command:set iskeyword& 1 options.txt 2 Normal 3 102
  • 103. 103 05 Vim Vim ex command:set nowrap Vim 1 10 ex command:set sidescroll=10 Vim 2 whichwrap ex command:set whichwrap=b,s 3 ex command:set whichwrap=b,s,<,> Normal Insert 1 context . 2 :-) 3 h, l h, l :set whichwrap+= l,h 103
  • 104. 104 05 Vim ex command:set whichwrap=b,s,<,>,[,] whichwrap ex command:set list ^I $ GUI, Vim listchars ex command:set listchars=tab:>-,trail:- 1 ">---" "-" iskeyword word ex command:set iskeywordiskeyword=@,48-57,_,192-255 > "@" "48-57" ASCII 48 57 0 9. "192-255" word "w" "upper-case" word ex command:set iskeyword+=-:set iskeywordiskeyword=@,48-57,_,192-255,- 1 :set list 104
  • 105. 105 05 Vim Vim "-=" ex command:set iskeyword-=_:set iskeywordiskeyword=@,48-57,192-255,- Vim Vim 1 cmdheight ex command:set cmdheight=3 ... |usr 06.txt| Using syntax highlighting |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 1 105
  • 106. 106 06*usr 06.txt* Vim 7.0 . 2006 04 24 VIM --- Bram Moolenaar 0 1 2 4 3 0 1 2 3 4 5 6 7 ; mecho -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 106
  • 107. 107 06 Vim ":syntax enable" |vimrc| |vimrc| ex commandif &t_Co > 1 syntax enableendif 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 107
  • 108. 108 06 |xterm-color| Vim ( xterm).- Vim ex command:set filetype "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 108
  • 109. 109 06 ex command:set background=dark ex command:set background=light ":syntax enable" background ":syntax reset" Vim- Vim 1 2 CTRL-L Tex |tex.vim|*06.3* GUI Edit/Color Scheme ex command:colorscheme evening "evening" $VIMRUNTIME/colors |vimrc| ":colorscheme"1 Vim Unix 2 <qujianning@gmail.com> PDF TEX/L TEX A ! 109
  • 110. 110 06 ex command!mkdir ~/.vim/colors!cp $VIMRUNTIME/colors/morning.vim ~/.vim/colors/mine.vim Vim $VIMRUNTIME 2 Listtermctermctermfgctermbggui GUIguifg GUIguibg GUI 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* 110
  • 111. 111 06 ex command:syntax clear ( ) :syn-off ex command:syntax off :syn-manual ex command:syntax manual syntax ex command:set syntax=ON*06.5* MS-Windows Vim ex command:hardcopy Vim 111
  • 112. 112 06 Vim Vim Listprintdeviceprintheaderprintfontprintoptions Visual normal mode commandv100j:hardcopy "v" Visual "100j" 100 ":hardcopy" Visual Unix PostScript HTML Netscape HTML HTML ex command:source $VIMRUNTIME/syntax/2html.vim HTML ( ): ex command:write main.c.html Vim |2html.vim| HTML HTML Web 112
  • 113. 113 06*06.6*|usr 44.txt| |syntax| |usr 07.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 113
  • 114. 114 07*usr 07.txt* Vim 7.0 . 2006 04 24 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 114
  • 115. 115 07 DisplayE37: No write since last change (use ! to override) : Vim ID ID: :help E37 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 Vim 3 Vim ex command:next 1 115
  • 116. 116 07 ":next" ":edit" ex command:next! ex command:wnext 1 : ex command:write:next ? "(2 of 3)" 3 2 ex command:args "arguments" Displayone.c [two.c] three.c Vim 1 Vim 116
  • 117. 117 07 ex command:previous ":next" ex command:wprevious ex command:last ex command:first ":wlast" ":wfirst" ":next" ":previous" 2 ex command:2next 1 ":write" Vim ex command:set autowrite ex command:set noautowrite 1 word Vim 117
  • 118. 118 07 Vim 3 ex command:args five.c six.c seven.h shell ex command:args *.txt Vim ":args!"( !) ? *arglist-quit* Vim Vim DisplayE173: 46 more files to edit ( )*07.3* CTRL-^( ^ 6 ) ex command:args one.c two.c three.c one.c. ex command:next 118
  • 119. 119 07 two.c CTRL-^ one.c CTRL-^ two.c ex command:next three.c CTRL-^ ":next" ":previous" "alternate" Vim normal mode command`" normal mode command` "one.txt" "x" "G" ":w" ":edit one.txt" `" Vim `. "x" `" `. 4 "mx" "`x" 119
  • 120. 120 07 "foo.txt" ("50%") F (F foo): normal mode command50%mF "bar.txt" B(B bar) normal mode commandGmB "´F" foo.txt "´B" bar.txt Vim 1 H header M Makefile, C C "marks" ex command:marks M ex command:marks MCP CTRL-O CTRL-I*07.4* Vim 1 120
  • 121. 121 07 ex command:set backup ~ data.txt, data.txt~ ex command:set backupext=.bak data.txt.bak backupdir : backup writebackup Vim ( ) patchmode Vim ex command:set patchmode=.orig data.txt Vim "data.txt.orig" Vim "data.txt.orig" "data.txt~"( backupext ). 121
  • 122. 122 07 patchmode ( )*07.5* "v" Visual "y" yanks( ) 1 : ex command:edit thisfile/Thisvjjjj$y "p" ex command:edit otherfile/Therep yank "V" Visual CTRL-V "Y" "yaw" yank-a-word "p" "P" Vim 1 122
  • 123. 123 07 Vim a z 26 ( ) f (f first): normal mode command"fyas "yas" Vim f "f. 3 l (l line): normal mode command"l3Y "l b (b block): normal mode commandCTRL-Vjjww"by "b y w" f, l b 3 normal mode command"fp "f p 3 1 word w normal mode command"wdaw 1 123
  • 124. 124 07 "d" ex command:write >> logfile "logfile" log ":write" Visual 10*07.6* ":w" Vim: shell commandvim -R file 1 Unix : shell commandview file "file" ":w" DisplayW10: Warning: Changing a readonly file 1 MS-Windows MS-DOS 124
  • 125. 125 07 1 ":write" ! shell commandvim -M file DisplayE21: Cannot make changes, modifiable is off -M Vim viewer ex command:set modifiable:set write*07.7* ex command:edit copy.c ":saveas" ex command:saveas move.c 1 ! 125
  • 126. 126 07 Vim ":write" "move.c" "copy.c" 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 " " 126
  • 127. 127 08*usr 08.txt* Vim 7.0 . 2006 07 18 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 127
  • 128. 128 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 128
  • 129. 129 08 1*08.2* ex command:split two.c one.c Display+----------------------------------+|/* file two.c */ ||~ ||~ ||two.c=============================||/* file one.c */ ||~ ||one.c=============================|| |+----------------------------------+ ex command:new 2 ":split" ":new"*08.3* 1 gvim "E445: " 2 17 5 129
  • 130. 130 08 ":split" 3 1 alpha.c : ex command:3split alpha.c normal mode commandCTRL-W + normal mode commandCTRL-W - "4 CTRL-W +" 4 normal mode command{height}CTRL-W _ {height}, CTRL-W ( Shift - ). CTRL-W 2 Vim 1 3 2 W CTRL 130
  • 131. 131 08 winheight winminheight :winwidth winminwidth equalalways Vim*08.4* ":split" ex command :vsplit :vsplit two.c Display+--------------------------------------+|/* file two.c */ |/* file one.c */ ||~ |~ ||~ |~ ||~ |~ ||two.c===============one.c=============|| |+--------------------------------------+ | ":vnew" ex command:vertical new 131
  • 132. 132 08 1 ":vertical" ( ). DisplayCTRL-W hCTRL-W jCTRL-W kCTRL-W lCTRL-W tCTRL-W b 2 . |Q w|*08.5* 1 :vertical echo"hello" 2 hljk CTRL-W hljk (W) 132
  • 133. 133 08 Display+----------------------------------+|/* file two.c */ ||~ ||~ ||two.c=============================||/* file three.c */ ||~ ||~ ||three.c===========================||/* file one.c */ ||~ ||one.c=============================|| |+----------------------------------+ ( CTRL-W w) normal mode commandCTRL-W K K 1 K CTRL-W K Vim Display+-------------------------------------------+|/* two.c */ |/* three.c */ |/* one.c */ ||~ |~ |~ ||~ |~ |~ ||~ |~ |~ ||~ |~ |~ ||~ |~ |~ ||two.c=========three.c=========one.c========|| |+-------------------------------------------+ 1 133
  • 134. 134 08 1 (three.c) CTRL-W K : Display+-------------------------------------------+|/* three.c */ ||~ ||~ ||three.c====================================||/* two.c */ |/* one.c */ ||~ |~ ||two.c==================one.c===============|| |+-------------------------------------------+ ( ): DisplayCTRL-W HCTRL-W JCTRL-W L2*08.6* Vim ex command:qall "quit all"3 Vim ":write" ":quit!" 1 CTRL-W L 2 3 134
  • 135. 135 08 ex command:wall "write all"1 Vim ":qall" ":wall" ex command:wqall Vim. Vim ex command:qall! "-o" Vim shell commandvim -o one.txt two.txt three.txt Display+-------------------------------+|file one.txt ||~ ||one.txt========================||file two.txt ||~ ||two.txt========================||file three.txt ||~ ||three.txt======================|| |+-------------------------------+ 1 135
  • 136. 136 08 "-O" vim, ":all" ":vertical all"*08.7* vimdiff Vim "main.c" backup "main.c~" shell ( Vim ): shell commandvimdiff main.c~ main.c Vim Display VV VV+-----------------------------------------+|+ +--123 lines: /* a|+ +--123 lines: /* a| <- fold| text | text || text | text || text | text || text | changed text | <- changed line| text | text || text | ------------------| <- deleted line| text | text || text | text || text | text ||+ +--432 lines: text|+ +--432 lines: text| <- fold| ~ | ~ || ~ | ~ ||main.c~==============main.c==============|| |+-----------------------------------------+ 136
  • 137. 137 08 ( vimdiff ) "<-fold" 123 "<- changed" man.c "---" "<-delete line" main.c "VV" "zo" "zc" VIM diff Vim 1 "main.c" : ex command:edit main.c:vertical diffsplit main.c ":vertical" patch diff 3 diff patch Vim patch ex command:edit main.c:vertical diffpatch main.c.diff 1 diff ?? 137
  • 138. 138 08 patch patch ( ). 1 Vim ex command:set noscrollbind normal mode command]c normal mode command[c Vim ex command:diffupdate 1 138
  • 139. 139 08 "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 List01 ( )2 "s" ":tag" tag, ":stag" tag. 1 "diff get") ("dg", pending 3j 4 139
  • 140. 140 08 Normal CTRL-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 Display+----------------------------------+| thisfile | /thatfile/ __________X| (thatfile is bold)|/* thatfile */ ||that ||that ||~ ||~ ||~ || |+----------------------------------+ 140
  • 141. 141 08 "thisfile" "thatfile" "thisfile" Display+----------------------------------+| /thisfile/ | thatfile __________X| (thisfile is bold)|/* thisfile */ ||this ||this ||~ ||~ ||~ || |+----------------------------------+ "gt" GotoTab. ex command:tab split Display+-------------------------------------+| thisfile | /thisfile/ | thatfile __X| (thisfile is bold)|/* thisfile */ ||this ||this ||~ ||~ ||~ || |+-------------------------------------+ 141
  • 142. 142 08 ":tab" Ex ex command:tab help gt "gt" List- "gt"- "X"-- "tabonly" |tab-page| |usr 09.txt| GUI |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 142
  • 143. 143 09 GUI*usr 09.txt* Vim 7.0 . 2006 04 24 VIM --- Bram Moolenaar GUI Vim GVim Vim GUI GVim Vim GUI|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.txtvim -g file.txt Vim GUI Vim "file.txt" Vim ( ASCII !). 143
  • 144. 144 09 GUI Display+----------------------------------------------------+| file.txt + (~/dir) - VIM X | <- window title+----------------------------------------------------+| File Edit Tools Syntax Buffers Window Help | <- menubar+----------------------------------------------------+| aaa bbb ccc ddd eee fff ggg hhh iii jjj | <- toolbar| aaa bbb ccc ddd eee fff ggg hhh iii jjj |+----------------------------------------------------+| file text | ^ || ~ | # || ~ | # | <- scrollbar| ~ | # || ~ | # || ~ | # || | V |+----------------------------------------------------+ Vim Vim List- ( )+==+ Vim Edit/Global Settings 144
  • 145. 145 09 GUI ListToggle Toolbar /Toggle Bottom Scrollbar /Toggle Left Scrollbar /Toggle Right Scrollbar / ( ) "Edit/Global Settings/Toggle Toolbar" vimrc ex command:set guioptions-=T guioptions "T" GUI "Edit/GlobalSettings/Toggle Bottom Scrollbar" diff wrap ( ) 1 guioptions 1 MS-Windows 145
  • 146. 146 09 GUI ex command:set guioptions+=l "l" guioptions*09.2* Windows X windows Vim Xwindows XWindow ex command:behave xterm ex command:behave mswin UNIX xterm Windows |:behave|XTERM List Visual List Visual Shift 146
  • 147. 147 09 GUI Listmouse Vimmousemodelmousetimemousehideselectmode Visual*09.3* |04.7| X-windows MS-Windows X-Windows " " Vim Visual ( ) Vim Visual gVim " " gVim " " Visual " " " " " " Edit/Copy " " 147
  • 148. 148 09 GUI ( KDE klipper ). gVim Edit/Paste " " " " " " gVim 1. Visual . 2. Edit/Copy . 3. Visual . 4. Edit/Paste 5. . " " " " " " " ". "* " " " " Visual "V" " " normal mode command"*P "P" "p" "+ " " 148
  • 149. 149 09 GUI normal mode command"+y$ "y" yank Vim " " normal mode command"+P " " + *.*09.4* MS-Windows X-Windows Visual Visual Select ( MS-Windows ): ex command:set selectmode+=mouse Visual Insert Normal "hjkl", "w" Shift <S-Left>( Shift ) Visual Shift+ <S-End> <S-Home> selectmode Select |usr 10.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 149
  • 150. 150 10*usr 10.txt* Vim 7.0 . 2006 11 05 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} a z 2 1 :-) 2 a z 150
  • 151. 151 10 1 2 3 q ( q ). "@{recording}" Liststdio.hfcntl.hunistd.hstdlib.h List#include "stdio.h"#include "fcntl.h"#include "unistd.h"#include "stdlib.h" Listqa a^i#include "<Esc> #include "$a"<Esc> "jq 2 3 "@" "@a" 1 2 VIM 151
  • 152. 152 10 normal mode command3@a ( 4 ) "@a" "@a" "@@" "@a" "@b" "@@" "@b" "." "." "@a" "." 26 26 yank n ListGo<Esc>"np n{edits}0"ny$ ndd "@n" ( n ) 152
  • 153. 153 10 word c word normal mode commandqC/word<Enter>q "qC" c yank yank normal mode command"aY 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" 153
  • 154. 154 10 "%" ":s" |10.3| ":substitute" DisplayProfessor Smith criticized Professor Johnson today. DisplayTeacher Smith criticized Professor Johnson today. "g" 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 : 1 CTRL-E CTRL-Y 154
  • 155. 155 10 Listyna ( ?? :-) )qlCTRL-ECTRL-Y "from" 1 "the" "these": ex command:s/^the/these/ / / 2 : ex command:s+one/two+one or two+*10.3* ":substitute" ":" ex command:1,5s/this/that/g 1 5 1 5 1 Vim 2 / 155
  • 156. 156 10 ex command:54s/President/Fool/ "."1 . ":write" ex command:.write otherfile 1 "$" yes no: ex command:.,$s/yes/no/ "%" "1,$" "grey" "gray" "grey" "Chapter" ex command:?^Chapter?,/^Chapter/s=grey=gray=g "?^Chapter?" "/^Chapter/" liao /, ":s" "=" "grey" ex command/Chapter/-1 1 156
  • 157. 157 10 1 2 ex command/Chapter/+2 ex command:.+3,$-5 3 61 3 "mt" "mb" :( ) ex command:t,bVisual Visual ":" ex command:<,> <,> Visual : Visual CTRL-V Vim < > Visual Visual Visual "<" Visual 1 $-1 offset by one 157
  • 158. 158 10 ex command:>,$ 1 Visual ":" "5:" ex command:.,.+4 "."( ) ".+4"( 4 ). 5*10.4* ":global" Vim ex command:[range]global/{pattern}/{command} ":substitute" {command} : ":global" ":" Normal |:normal| Normal C++ "foobar" "barfoo"( "//" ): ex command:g+//+s/foobar/barfoo/g 1 <yangxcmail-linux@yahoo.com.cn> Bug Report " " " " 158
  • 159. 159 10 ":g" ":global" ":s" ":substitute" / "foobar" "barfoo" ":substitute" "//" "//" "foobar" 1 ":substitute" Vim*10.5* Visual block CTRL-V 2 Vim Visual block "$" "j" "h" "Istring<Esc>" CTRL-V Visual block I <Esc> 1 puts("foobar"); // this line contains a foobar 2 "$" 159
  • 160. 160 10 Displayinclude oneinclude twoinclude threeinclude four "one" "o" CTRL-V "3j" 3 "four" 4 normal mode commandImain.<Esc> Displayinclude main.oneinclude main.twoinclude main.threeinclude main.four "long" "long" 2 DisplayThis is a long lineshortAny other long line ^^^^ selected block "Ivery <Esc>" DisplayThis is a very long lineshortAny other very long line "short" 160
  • 161. 161 10 "I" Normal "A" "I" I A Visual "A" "$" "A" "$A XXX<Esc>" DisplayThis is a long line XXXshort XXXAny other long line XXX "$" Vim 1 Visual block "c" Insert 2 "long" "c LONG <Esc>" DisplayThis is a _LONG_ lineshortAny other _LONG_ line "I" 3 "C" 1 "$" : This is a long line XXX short XXX Any other long line XXX 2 <Esc> 3 161
  • 162. 162 10 1 Insert "Cnew text <Esc>" DisplayThis is a new textshortAny other new text "long" Visual block List~ (a -> A, A -> a)U (a -> A, A -> A)u (a -> a, A -> a) "r" "rx" DisplayThis is a xxxx lineshortAny other xxxx line : 25 virtualedit ">" "shift "2 ">" DisplayThis is a long lineshortAny other long line 1 2 "shift " :set sw=N N :h sw 162
  • 163. 163 10 shiftwidth 4 ex command:set shiftwidth=4 "<" "shift " ">" 1 "shift " "J" 2 3 ( joinspaces ). "J" DisplayThis is a long line short Any other long line "J" Visual block "v" 4 "V" "gJ" "J"*10.6* e-mail ":read {filename}" 1 2 <Tab> <Tab> /^s+/ /s+$/, TODO 3 4 163
  • 164. 164 10 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 <= length; ++i)---> for (i = 0; i < length; ++i)Bye, Pierre. ":read" ":$r patch" "patch" 0 0 "read" ex command:0read patch "patch" ":write" ex command:.,$write tempo 164
  • 165. 165 10 "tempo" "tempo" Vim "write" ex command:.,$write! tempo ! ":write" 1 ex command:.write collection ex command:.write >>collection ">>" Vim "collection"*10.7* 2 textwidth : ex command:set textwidth=72 vimrc vimrc 1 2 textwidth textwidth textwidth 165
  • 166. 166 10 ex command:set textwidth 72 Vim Vim normal mode commandgqap "gq" Vim "ap", "a paragraph" : "ap" normal mode commandgggqG "gg" "gq" Vim "G" "gqj" 1 "."*10.8* [[ ]] 1 Vim /w+/ 166
  • 167. 167 10 section header1 "section" "gU" 2 "gu" "gU" Display guwSECTION header ----> section header "g~" 3 Visual "d" "dd" "gugu" "guu". "gUgU" "gUU", "g~g~" 4 "g~~" . Display g~~Some GIRLS have Fun ----> sOME girls HAVE fUN*10.9* 5 Vim "!{motion}{program}" {program} {motion} {motion} 1 2 section 3 Vim operator command motion text object? " " a + b 4 "3dd" 3 5 167
  • 168. 168 10 UNIX sort input.txt output.txt. ( UNIX Microsoft Windows). shell commandsort < input.txt > output.txt Vim 1-5 1 normal mode command!5G "!" Vim Vim "5G" Vim 5 Vim 1 ( ) 5 1 Vim "sort" normal mode command!5Gsort<Enter> sort 5 5 Displayline 55 line 11line 33 line 22line 11 --> line 33line 22 line 44line 44 line 55last line last line "!!" Unix "date" "!!date<Enter>" "date" 1 : {motion} Vim Normal Normal Normal 168
  • 169. 169 10 ? Vim shell shell Vim shell shellcmdflag shell shellquote shell shellxquote shell a shelltype shell ( Amiga ) shellslash ( MS-Windows ) shellredira Amiga Unix shell: "sh" "csh" Vim shell "csh" MS-Windows shell Unix: ex command:read !lsMS-Windows: ex command:read !dir "ls" "dir" Vim "!" Vim Vim 169
  • 170. 170 10 ex command:0read !date -u UTC ( date "-u" ) "!!date" "!!date" ":read !date" 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 1 : 2 170
  • 171. 171 10 |usr 11.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 171
  • 172. 172 11*usr 11.txt* Vim 7.0 . 2006 04 24 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 nameand run diff with the original file to check for changes)Delete the .swp file afterwards. 172
  • 173. 173 11 ex command:write help.txt.recovered Vimdiff |08.7| ( ) ( Vim ) Vim Vim 4 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 173
  • 174. 174 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 174
  • 175. 175 11 : Vim dir "filename.sw?" ( shell ), Vim "filename.swp"*11.3* ? Vim Vim Display E325: ATTENTIONFound a swap file by the name ".main.c.swp" owned by: mool dated: Tue May 29 21:09:28 2001 file 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 "process ID" 175
  • 176. 176 11 Displayprocess ID: 12559 (still running) "(still running)" Unix Vim Vim. 2 Vim Vim Displaymodified: YES Vim ( ) ( ) Vim DisplayNEWER than swap file! Display[cannot be read] 0 1 1 ? 176
  • 177. 177 11 "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 .E Vim Vim .R .Q Vim Vim Vim Vim 1 .A . 1 Vim 177
  • 178. 178 11D Unix . ( Vim) ex command:recover Vim Vim. shortmess 1 "A"*11.4* |swap-file| |:preserve| |:swapname| updatecount updatetime swapsync directory maxmem maxmemtot |usr 12.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 1 A ATTENTION 178
  • 179. 179 12*usr 12.txt* Vim 7.0 . 2007 05 11 VIM --- Bram Moolenaar Vim|12.1| word|12.2| "Last, First" "First Last"|12.3||12.4||12.5| 1|12.6||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" "<" word 1 Unix 179
  • 180. 180 12 ex command:%s/<four/4/g "fourteen" ">" word ex command:%s/<four>/4/g "four" "c" ex command:%s/<four>/4/gc C++ ".cpp" "GetResp" "GetAnswer". vim *.cpp Vim C++ qq q :%s/<GetResp>/GetAnswer/g :wnext q @q q ":wnext 1 999@q ":wnext" "next" 2 2 Vim 180
  • 181. 181 12 : .cpp "GetResp" "e" ex command:%s/<GetResp>/GetAnswer/ge "e" ":substitute"*12.2* "Last, First" "First Last" DisplayDoe, JohnSmith, Peter DisplayJohn DoePeter Smith Vim ex command:%s/([^,]*), (.*)/2 1/ "%" "/from/to/" "from" "to" "from" 181
  • 182. 182 12 Display ([^,]*), (.*) ( ) "Last" ( ) [^,] * ", " , ( ) "First" ( ) . * "to" "2" "1" Vim ( ) "2" "()" "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/^OBJSj:.,/^$/-1!sort 182
  • 183. 183 12 "OBJS" sort Visual "!sort" DisplayOBJS = backup.o getopt.o getopt1.o inp.o patch.o pch.o util.o version.o "backup.o" 1 "A <Esc>"*12.4* |:global| |:move| ex command:global/^/m 0 ex command:g/^/m 0 1 Makefile 183
  • 184. 184 12 "^" ( ).|:move| 0 |:global| 1 "mt" 2 : ex command:t+1,.g/^/m t*12.5* --- Vim normal mode commandg CTRL-G "g" DisplayCol 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 1 Join 2 :10,20g/^/m9 184
  • 185. 185 12 |count-items|*12.6* [[ Unix ]] Vim shell C ( Unix ) : normal mode commandK Vim "man" ( "more" ) <Enter> Vim. man Vim man plugin: ex command:source $VIMRUNTIME/ftplugin/man.vim vimrc 1 ":Man" man ex command:Man csh "CTRL-W w" 3 "echo" ex command:Man 3 echo 1 Man Vim unix man 185
  • 186. 186 12 man man "word(1)", CTRL-] ":Man" 1 man normal mode commandK ( <Leader> ). "strstr()" codeif ( strstr (input, "aap") == ) "strstr" "K". Vim 2 strstr() man .*12.7* ex command:%s/s+$// "%" ":substitute" "s+$". |usr 27.txt| ":substitute" "to" :"//" 1 (1) man CTRL-] "word(1)" man man Vim man man (2) man "word.~" (3) :vertical Manls 2 man.vim "K" 186
  • 187. 187 12 normal mode command/ "/<Space><Tab>" "x" "n"*12.8* word UNIX Vim grep "frame counter" C shell commandvim `grep -l frame_counter *.c` grep "-l" "frame counter" ( grep Vim 1 .) 2 UNIX shell grep Vim 3 ":next" ":first" 1 Mastering the Regular Expression 2 ":substitute" 1 3 MS-DOS grep Cygwin grep SHELL ` 187
  • 188. 188 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: 188
  • 189. 189 20*usr 20.txt* Vim 7.0 . 2006 04 24 VIM --- Bram Moolenaar Vim|20.1||20.2||20.3||20.4||20.5| |usr 21.txt| |usr 12.txt| |usr toc.txt|*20.1* / ? Vim <BS> ex command:s/col/pig/ <Enter> "col" "cow" <Left>5 "col" <BS> "w" ex command:s/cow/pig/ 189
  • 190. 190 20 List<Left><Right><S-Left> <C-Left><S-Right> <C-Right>CTRL-B <Home>CTRL-E <End> : <S-Left>( Shift ) <C-Left>( CTRL ) Shift CTRL <BS> CTRL-W normal mode command/the fine pig CTRL-W/the fine CTRL-U <Insert> normal mode command/the fine pig 2 <S-Left>( <S-Left> 8 ) "fine" <Insert> "great" 190
  • 191. 191 20 normal mode command/the greatpig <BS> "t"( ) <Insert> normal mode command/the great pig CTRL-C <Esc> : <Esc> " " Vi <Esc> bug Vim <Esc> cpoptions Vim Vi ( Vi )<Esc> a Vi CTRL-C .) a CTRL-W <Esc> CTRL-W CTRL-C <BS> ":" "/"*20.2* ":substitute" ":s". Vim 26 ":set" ":s" ":s" ":set", ":set" ":se" 191
  • 192. 192 20 good good study Display:s[ubstitute] ":substitute" ":s" ":su" ":sub" ":function" ":fu" ":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* Vi Vim 1 3 1 << >> " ~~~~!" 192
  • 193. 193 20 Listinfo.txtintro.txtbodyofthepaper.txt ex command:edit bodyofthepaper.txt ex command:edit b<Tab> <Tab> "b". Vim "b" Vim ex command:edit i<Tab> Vim ex command:edit info.txt Vim ( ) <Tab> ex command:edit intro.txt <Tab> <Tab> ex command:edit i 193
  • 194. 194 20 Vim CTRL-P Display <------------------- <Tab> -------------------------+ | <Tab> --> <Tab> -->:edit i :edit info.txt :edit intro.txt <-- CTRL-P <-- CTRL-P | +---------------------- CTRL-P ----------------------> ":edit i" ":set i" <Tab> ex command:set icon ":set info.txt" Vim Vim ":set" <Tab> Vim ex command:set isk<Tab> ex command:set iskeyword "=" <Tab>: ex command:set iskeyword=@,48-57,_,192-255 Vim 194
  • 195. 195 20 Vim <Tab> Vim ( ^I ). CTRL-D. CTRL-D: ex command:set is ex command:set isincsearch isfname isident iskeyword isprint:set is Vim <BS> <Tab> "incsearch" "is" "is" ( )Vim CTRL-L ":edit i" "info.txt" "info backup.txt" ":edit info" wildmode .wildmenu .suffixes . 1wildignore 1 (1)Vim (2)Vim 195
  • 196. 196 20 |cmdline-completion|*20.4* 3 4 "/" "?" "/" "?" input() |cmdline-history| ":set" 10 ":set" ":" 10 <Up> ex command:se<Up> Vim "se" ":set" 10 <Up> ( 10 ":set" ). <Up> <Down> CTRL-U ex command:history 1 : ex command:history / 1 : map, autocommand, tags 196
  • 197. 197 20 CTRL-P <Up> <Down> CTRL-N CTRL-P 1 previous CTRL-N Next*20.5* [[ Vim ]] 2 : normal mode commandq: Vim ( ) 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" 1 CTRL-P CTRL-N shell emacs 2 normal 197
  • 198. 198 20 ":e config.h.in" . "$h" "in" "i" "cwout" ex command:e config.h.out Vim Insert Normal 1 "?config" "config" 2 |usr 21.txt| Go away and come back |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 1 :-) 2 CTRL-W c Vim CTRL-C <Esc> :q 198
  • 199. 199 21*usr 21.txt* Vim 7.0 . 2007 05 01 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* Unix Vim CTRL-Z Vim Vim shell "fg" Vim. shell commandCTRL-Z{ shell }fg 199
  • 200. 200 21 CTRL-Z ":suspend" Vim Unix Vim shell shell shell 1 Vim GUI Vim Vim shell CTRL-Z 2*21.2* shell shell Vim ":!{command}" ex command:!ls:!dir Unix MS-Windows. Vim "!" ex command:!{program} {program}:r !{program} {program}:w !{program} {program}:[range]!{program} {program} 3 "!{program}" 1 shell 2 windows gvim CTRL-Z u :unmap <CTRL-Z> CTRL-Z 3 ? 200
  • 201. 201 21 shell shell: ex command:shell CTRL-Z Vim shell. GUI Vim shell Vim Vim guipty shell ex command:!xterm&*21.3* viminfo Vim viminfo List Vim viminfo Vim viminfo 201
  • 202. 202 21 ex command:set viminfo=string string / viminfo string (a-z) ( 1000) ex command:set viminfo=1000 f (A-Z 0-9) 0 1 f ex command:set viminfo=1000,f1 < 0 viminfo ( Vim ) 500: ex command:set viminfo=1000,f1,<500 List:@/r ( )!h hlsearch% ( Vim )c encodingn viminfo ( ) 202
  • 203. 203 21 viminfo |viminfo-file| Vim Vim Vim Vim normal mode command0 Vim 0 0 1 1 2 9 |:marks| 0 9 VIM viminfo 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 1 ! 203
  • 204. 204 21 1*21.4* Vim 2 Vim ( sessionoptions ) ex command:mksession vimbook.vim ex command:source vimbook.vim Vim shell commandvim -S vimbook.vim Vim S session( -S Vim "source"). sessionoptions"blank,buffers,curdir,folds,help,options,winsize" Listblankbufferscurdirfolds foldshelpoptionswinsize 1 viminfo 2 204
  • 205. 205 21 Vim ex command:set sessionoptions+=resize "~/.vim" "secret" "boring" ex command:wall:mksession! ~/.vim/secret.vim:source ~/.vim/boring.vim ":wall" ":mksession!" "secret" "boring" ex command:source ~/.vim/boring.vim 205
  • 206. 206 21 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:helpCTRL-W w:vertical split ~/ ex command:mksession ~/.vim/mine.vim Vim: ex commandvim -S ~/.vim/mine.vim "O" 206
  • 207. 207 21UNIX MS-WINDOWS MS-Windows Unix "slash" "unix" sessionoptions ex command:set sessionoptions+=unix,slash Vim Unix MS-Windows Vim Unix Unix Vim MS-Windows MS-Windows Vim / Unix Vim 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 207
  • 208. 208 21 number folds Vim ex command:mkview Vim 1 : ex command:loadview number folds ex command:mkview 1 ex command:loadview 1 ":loadview" 10 1 9 Vim 1 Vim VIM viewdir E:worktipsvim.tip :mkview "E=-=+work=+tips=+vim.tip=" :loadview Vim view 208
  • 209. 209 21 ex command:mkview ~/.vim/main.vim ex command:source ~/.vim/main.vim*21.6* Vim C 4 shiftwidth 4 Display/* vim:set shiftwidth=4: */ 5 5 shiftwidth 4 :8. modelines Vim 10 ex command:set modelines=10 modeline Unix root MS-Windows 209
  • 210. 210 21 ex command:set nomodeline codeany-text vim:set {option}={value} ... : any-text "any-text" Vim /* */. Vim " vim:" "vim" "vim" "gvim:" ":set" ":set" code// vim:set textwidth=72 dir=c:tmp: use c:tmp here ":set" |modeline| |usr 22.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 210
  • 211. 211 22*usr 22.txt* Vim 7.0 . 2007 08 14 VIM --- Bram Moolenaar Vim Vim|22.1||22.2||22.3||22.4| |usr 23.txt| |usr 21.txt| |usr toc.txt|*22.1* Vim ex command:edit . Vim 211
  • 212. 212 22 Display" ============================================================================" Netrw Directory Listing (netrw v109)" Sorted by name" Sort sequence: [/]$,.h$,.c$,.cpp$,*,.info$,.swp$,.o$.obj$,.bak$" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec" ============================================================================.././check/Makefileautocmd.txtchange.txteval.txt~filetype.txt~help.txt.info Display1.2.3. ( , )4. , ( , .h , *.c5. ( VimSpecialChar{F1} ), .6. , VimDQuote{../}. Normal Vim <Enter> ":edit ." ":Explore" CTRL-O <Enter> "../" <Enter> "-" "-" <F1> netrw : 212
  • 213. 213 22 Display 9. Directory Browsing netrw-browse netrw-dir netrw-list netrw-help MAPS netrw-maps <F1>.............Help.......................................|netrw-help| <cr>.............Browsing...................................|netrw-cr| <del>............Deleting Files or Directories..............|netrw-delet -................Going Up...................................|netrw--| a................Hiding Files or Directories................|netrw-a| mb...............Bookmarking a Directory....................|netrw-mb| gb...............Changing to a Bookmarked Directory.........|netrw-gb| c................Make Browsing Directory The Current Dir....|netrw-c| d................Make A New Directory.......................|netrw-d| D................Deleting Files or Directories..............|netrw-D| <c-h>............Edit File/Directory Hiding List............|netrw-ctrl- i................Change Listing Style.......................|netrw-i| <c-l>............Refreshing the Listing.....................|netrw-ctrl- o................Browsing with a Horizontal Split...........|netrw-o| p................Use Preview Window.........................|netrw-p| P................Edit in Previous Window....................|netrw-p| q................Listing Bookmarks and History..............|netrw-q| r................Reversing Sorting Order....................|netrw-r| ( ...) <F1> netrw vim |CTRL-]| |CTRL-O| : ( ) Display<Enter> |netrw-cr|o |netrw-o|v |netrw-v|p |preview-window| |netrw-p|p |preview-window| |netrw-P|t |netrw-t| netrw : 213
  • 214. 214 22 Displayi ( , , , ),s s : , , .r normal : Listc ( |g:netrw_keepdir| )R Vim aD Vim bmb gb /ab , : List :Explore [ ] :NetrwSettings netrw , netrw ; :( / ) List :Explore ftp://somehost/path/to/dir/ :e scp://somehost/path/to/dir/*22.2* shell Vim home "VeryLongFileName" ex command:edit VeryLongFileName/file1.txt:edit VeryLongFileName/file2.txt:edit VeryLongFileName/file3.txt 214
  • 215. 215 22 ex command:cd VeryLongFileName:edit file1.txt:edit file2.txt:edit file3.txt ":cd" "VeryLongFileName" 1 ":pwd" ex command:pwd/home/Bram/VeryLongFileName Vim "cd -" ex command:pwd/home/Bram/VeryLongFileName:cd /etc:pwd/etc:cd -:pwd/home/Bram/VeryLongFileName:cd -:pwd/etc Vim local directory. 1 pwd present working directory password 215
  • 216. 216 22 ex command:pwd/home/Bram/VeryLongFileName:split:lcd /etc:pwd/etcCTRL-W w:pwd/home/Bram/VeryLongFileName ":lcd" ":cd" ":lcd" ":cd" ":lcd" ":cd"*22.3* C code#include "inits.h" "inits.h" normal mode commandgf Vim Vim path "c:/prog/include" 216
  • 217. 217 22 ex command:set path+=c:/prog/include ex command:set path+=./proto Vim "gf" "proto" Vim "proto/inits.h" "./" "proto" Vim "proto" path path isfname Vim ( " ). ex command:find inits.h Vim path path ":edit" "CTRL-W f" 1 "gf" ":sfind" ":find" path shell commandvim "+find stdio.h" 1 :vertical sfind 217
  • 218. 218 22 path "stdio.h" |-+c|*22.4* Vim "one.txt" "two.txt" ":edit two.txt" "one.txt" "one.txt" Vim ex command:hide edit two.txt "one.txt" Vim ":hide" hidden 1 2 Vim Vim 1 hide vertical vertical 2 Vim :qa :wqa 218
  • 219. 219 22 ListActiveHiddenInactive Vim ex command:buffers ex command:ls :buffers 1 Display1 #h "help.txt" line 622 %a+ "usr_21.txt" line 13 "usr_toc.txt" line 1 ( ): 1 (1)ls ls :grep grep (2)Vim 219
  • 220. 220 22 Listu |unlisted-buffer|a % # l h = - modifiable +a :ls! :ls vi [ ] ex command:buffer 2 1 : ex command:buffer help Vim "help.txt" ex command:sbuffer 3 1 Vim filename.txt name Vim 220
  • 221. 221 22 List:bnext:bprevious:bfirst:blast ex command:bdelete 3 1 ( ) Vim : ":bdelete" Vim "unlisted" ":buffers" ":buffers!" ( Vim Misson Impossible) ":bwipe" buflisted |usr 23.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 1 221
  • 222. 222 23*usr 23.txt* Vim 7.0 . 2006 04 24 VIM --- Bram Moolenaar 10 Vim Vim Vim|23.1| DOS, Mac Unix|23.2||23.3||23.4||23.5| |usr 24.txt| |usr 22.txt| |usr toc.txt|*23.1* DOS, Mac Unix ( <CR>) ( <LF>). UNIX <LineFeed> <CR> MS-DOS( Windows) <CR><LF> 222
  • 223. 223 23 Vim fileformats Vim Vim UNIX MS-DOS ex command:set fileformats=unix,dos Unix Unix DOS Vim Display"/tmp/test" [dos] 3L, 71C "[mac]" fileformat ex command:set fileformat? 1 Vim Listunix <LF>dos <CR><LF>mac <CR> Unix <LF> <CR> Vi( Vim) Macintosh <CR> <LF> <CR> <LF> 100% Unix Mac Vim Unix 1 fileformat Vim 223
  • 224. 224 23 Mac "mac" fileformats ex command:set fileformats+=mac Vim Vi MS-DOS ^M (^M ) Vim ex command:edit ++ff=unix file.txt "++" Vim "++ff" fileformat. "++ff=mac" "++ff=dos" "++ff" "++enc" "++fileformat" "++encoding" fileformat MS-DOS README.TXT UNIX shell commandvim README.TXT Vim dos UNIX ex command:set fileformat=unix:write Unix*23.2* 224
  • 225. 225 23 email URL DisplayYou can find the information here: ftp://ftp.vim.org/pub/vim/README Vim URL normal mode commandgf Vim CTRL-W f. URL Vim netrw URL: Listftp:// uses ftprcp:// uses rcpscp:// uses scphttp:// uses wget (reading only) Vim Unix "ftp" "rcp" "scp" "wget" Vim URL ":edit" ":split" http:// / |netrw|*23.3* 225
  • 226. 226 23 Vim Vim "-x" shell commandvim -x exam.txt Vim / DisplayEnter encryption key: Vim DisplayEnter same key again: Vim "-x" ":edit" Vim 1 Vim Vim Vim ( ). key ex command:set key= 1 MS-DOS MZ Tiff 0x4949 226
  • 227. 227 23 key ":X" "-x" Display:XEnter encryption key: ******Enter same key again: ****** Vim -n (Vim ) "file.txt" shell commandvim -x -n file.txt ex command:setlocal noswapfile viminfo 227
  • 228. 228 23*23.4* Vim Vim Vim Vim "-b" shell commandvim -b datafile binary textwidth 0 Unix Vim "R" ex command:set display=uhex "ga" <Esc>1 Display<^[> 27, Hex 1b, Octal 033 wrap ex command:set nowrap 1 228
  • 229. 229 23 normal mode commandg CTRL-G ga DisplayCol 9-16 of 9-16; Line 277 of 330; Word 1806 of 2058; Byte 10580 of 12206 1 fileformat "go" 2345 ex command2345go xxd Vim "xxd" Vim shell commandvim -b datafile xxd ex command:%!xxd Display0000000: 1f8b 0808 39d7 173b 0203 7474 002b 4e49 ....9..;..tt.+NI0000010: 4b2c 8660 eb9c ecac c462 eb94 345e 2e30 K,.‘.....b..4^.00000020: 373b 2731 0b22 0ca6 c1a2 d669 1035 39d9 7;1.".....i.59. 1 1 1 0 229
  • 230. 230 23 Vim 1 ex command:%!xxd -r xxd*23.5* Vim "gzip" List.Z compress.gz gzip.bz2 bzip2 Vim |usr 24.txt| Inserting quickly |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 1 UltraEdit WinHex xxd -r 230
  • 231. 231 24*usr 24.txt* Vim 7.0 . 2006 07 23 VIM --- Bram Moolenaar Vim word word word|24.1||24.2||24.3||24.4||24.5||24.6||24.7||24.8||24.9||24.10| Normal |usr 25.txt| |usr 23.txt| |usr toc.txt|*24.1* <BS> <Del> ( ) word CTRL-W: DisplayThe horse had fallen to the sky CTRL-WThe horse had fallen to the 231
  • 232. 232 24 CTRL-U "fallen" "f" CTRL-U: DisplayThe horse had fallen to the CTRL-Ufallen to the word word DisplayThe horse had follen to the ground "follen" "fallen" List Insert <Esc> 4 word 4b "o" l "o" "a" ra Insert A List 4 word <C-Left><C-Left><C-Left><C-Left> "o" <Right> "o" <Del> "a" a <End> Insert ( <End> ). Insert Insert 232
  • 233. 233 24 List<C-Home><PageUp><Home><S-Left> word<C-Left> word<S-Right> word<C-Right> word<End><PageDown><C-End> |ins-special-specified|*24.2* ) ( Vim ex command:set showmatch "(example)" ) Vim ( ) ( Vim ( ) [] {} () ,ZZ matchtime Vim ex command:set matchtime=15*24.3* 233
  • 234. 234 24 1 2 Vim CTRL-P, Vim C codetotal = ch_array[0] + ch_array[1] + ch_array[2]; codetotal = ch_array[0] + ch_ CTRL-P Vim ch Vim word "ch " word ch array CTRL-P codetotal = ch_array[0] + ch_array ( ): codetotal = ch_array[0] + ch_array[1] + CTRL-P Vim word word word,"ch array" CTRL-P word: "total" CTRL-P word 4 CTRL-P "ch array" CTRL-N word CTRL-N CTRL-P word :CTRL-N Next-match3 , CTLR-P Previous-match4 Vim word 1 Vim 2 3 4 234
  • 235. 235 24 1. 2. 3. ( ) 4. ( ) 5. Tag 6. #include complete Vim word ignorecase word infercase word ( ignorecase ) "For" Vim "fortunately" "Fortunately" ListCTRL-X CTRL-FCTRL-X CTRL-LCTRL-X CTRL-D ( include )CTRL-X CTRL-I includeCTRL-X CTRL-K wordCTRL-X CTRL-T thesaurus wordCTRL-X CTRL-] tagsCTRL-X CTRL-V Vim CTRL-N CTRL-P |ins-completion| 235
  • 236. 236 24 CTRL-X CTRL-F word Listmain.c sub_count.c sub_done.c sub_exit.c DisplayThe exit code is in the file sub CTRL-X CTRL-F Vim "sub" sub count.c. CTRL-N sub done.c CTRL-N sub exit DisplayThe exit code is in the file sub_exit.c / (Unix) C:(MS-Windows) "/u" CTRL-X CTRL-F "/usr"( Unix ): Displaythe file is found in /usr/ CTRL-N "/u" "/usr/" CTRL-X CTRL-F: Displaythe file is found in /usr/X11R6/ ( "file " CTRL-X CTRL-F "file a", "file b" "file a" "file b") Vim Omni (intellisense) . 236
  • 237. 237 24 Omni <CTRL-X> <CTRL-O> O Omni C code { struct foo *p; p-> "->" <CTRL-X> <CTRL-O> Vim "foo" <CTRL-P> --- "foo" Omni vimrc Display filetype plugin on Display filetype plugin indent on C tags tags ft-c-omni compl-omni-filetypes omnifunc*24.4* CTRL-A insert code"file.h"/* Main program begins */ 237
  • 238. 238 24 "#include ": code#include "file.h"/* Main program begins */ "j^" "#include" normal mode commandi CTRL-A code#include "file.h"#include /* Main program begins */ insert "#include " CTRL-A "main.h"<Enter> code#include "file.h"#include "main.h"/* Main program begins */ CTRL-@ CTRL-A Insert CTRL-A*24.5* CTRL-Y C codeb_array[i]->s_next = a_array[i]->s_next; "s next" "s prev" 14 CTRL-Y, "next" "n" 238
  • 239. 239 24 codeb_array[i]->s_next = a_array[i]->s_next;b_array[i]->s_ "prev": codeb_array[i]->s_next = a_array[i]->s_next;b_array[i]->s_prev CTRL-Y "next": codeb_array[i]->s_next = a_array[i]->s_next;b_array[i]->s_prev = a_array[i]->s_ "prev;" CTRL-E CTRL-Y 1*24.6* CTRL-R {register} word coder = VeryLongFunction(a) + VeryLongFunction(b) + VeryLongFunction(c) 2 v normal mode command"vyiw "v "yiw" word 1 CTRL-E, CTRL-Y Normal 2 239
  • 240. 240 24 Displayr = CTRL-R v coder = VeryLongFunction CTRL-R v word CTRL-N CTRL-P word. <BS> 1 CTRL-R CTRL-R {register}*24.7* "ad" "advertisement". Vim Vim "ad" "advertisement": ex command:iabbrev ad advertisement "ad" word "advertisement" Vim word ListI saw the a I saw the aI saw the ad I saw the adI saw the ad<Space> I saw the advertisement<Space> 1 <BS> 240
  • 241. 241 24 "ad" "add" word word -- 1 word "JB" "Jack Benny": ex command:iabbrev JB Jack Benny ex command:iabbrev #b /****************************************:iabbrev #e <Space>****************************************/ #b #e #e - Vim 7 <, S, p, a, c, e, > : ":iab" ":iabbrev" "the" "teh" ex command:abbreviate teh the 1 " ", N " " " " . 241
  • 242. 242 24 ":abbreviations" Display:abbreviatei #e ****************************************/i #b /****************************************i JB Jack Bennyi ad advertisement! teh the "i" Insert Insert Listc :cabbrev! Insert :abbreviate ":iabbrev" "ad" ex command:edit ad ":unabbreviate" ex command:abbreviate f fresh @ ex command:unabbreviate f @ @ f 1 "fresh" Vim ( "fresh" ). 1 242
  • 243. 243 24 ex command:abclear ":unabbreviate" ":abclear" Insert (":iunabbeviate" ":iabclear") (":cunabbreviate" ":cabclear"). ex command:abbreviate @ a adder:imap dd disk-door a @ "adisk-doorer"1 ":noreabbrev" ex command:noreabbrev @ a adder*24.8* CTRL-V normal mode commandCTRL-V <Esc> escape Insert ( CTRl-V )2 1 dd word word 2 escape ASCII 27 " " " " 243
  • 244. 244 24 : MS-Windows CTRL-V CTRL-Q Unix CTRL-Q a a CTRL-V {digits} {digits} ASCII ASCII 127 <Del>( <Del> !) <Del> normal mode commandCTRL-V 127 0 255 Vim 0 3 3 <Tab> DisplayCTRL-V 9.CTRL-V 09.CTRL-V 009. ASCII CTRL-V "x": normal mode commandCTRL-V x7f 256 (ASCII 255 CTRL-V xff) "o" Vim 8 16bit 32bit ( Unicode ): normal mode commandCTRL-V o123CTRL-V u1234CTRL-V U12345678*24.9* 244
  • 245. 245 24 Vim digraphs ? normal mode commandCTRL-K Co ex command:digraphs digraphs Vim digraph DisplayAC ? 159 NS ? 160 !I ? 161 Ct ? 162 Pd ? 163 Cu ? 164 Ye ? 165BB ? 166 SE ? 167 : ? 168 Co ? 169 -a ? 170 << ? 171 NO ? 172-- ? 173 Rg ? 174 m ? 175 DG ? 176 +- ? 177 2S ? 178 3S ? 179 CTRL-K Pd (? ASCII 163( ). Pd Pound Digraphs Digraphs Digraphs CTRL-KdP CTRL-K Pd "dP" Vim Digraphs. : Digraphs Vim MS-DOS MS-Windows ":digraphs" Digraphs. digraphs ex command:digraph a" |d CTRL-K a" ? 245
  • 246. 246 24 ex command:digraph a" 228 Digraphs |digraphs| |45.5|*24.10* Normal Insert Normal Normal <Esc> Insert Normal "i" "a" Insert Vim CTRL-O {command} Insert Normal normal mode commandCTRL-O D Normal normal mode commandCTRL-O "g3dw 3 g |usr 25.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 246
  • 247. 247 25*usr 25.txt* Vim 7.0 . 2007 05 11 VIM --- Bram Moolenaar Vim|25.1||25.2||25.3||25.4||25.5| |usr 26.txt| |usr 24.txt| |usr toc.txt|*25.1* Vim 70 textwidth Vim 30 ex command:set textwidth=30 ( ): 247
  • 248. 248 25 Display 1 2 312345678901234567890123456789012345I taught programming for a whi "l" 30 Vim Display 1 2 312345678901234567890123456789012345I taught programming for awhil Display 1 2 312345678901234567890123456789012345I taught programming for awhile. One time, I was stoppedby the Fort Worth police,because my homework was toohard. True story. Vim : wrap Vim Vim Vim "programming" 248
  • 249. 249 25 Display 1 2 312345678901234567890123456789012345I taught for awhile. One time, I was stoppedby the Fort Worth police,because my homework was toohard. True story. "gq" Visual normal mode commandv4jgq "v" Visual "4j" "gq" Display 1 2 312345678901234567890123456789012345I taught for a while. Onetime, I was stopped by theFort Worth police, because myhomework was too hard. Truestory. : |auto-format| "gq" 3 Visual "gq4j" "}" "gq}" "gq" normal mode commandgqap 249
  • 250. 250 25 "ap" "a-paragraph" ( ) normal mode commandgggqG "gg" "gqG" ( ). " " Vim |fo-table| joinspaces Vim formatprg*25.2* ex command:{range}center [width] {range} [width] [width] textwidth. ( textwidth 0 80). ex command:1,5center 40 Display I taught for a while. One time, I was stopped by theFort Worth police, because my homework was too hard. True story. 250
  • 251. 251 25 ":right" ex command:1,5right 37 Display I taught for a while. One time, I was stopped by theFort Worth police, because my homework was too hard. True story. ex command:{range}left [margin] ":center" ":right" ":left" ( 0 ) 5 5 ex command:1left 5:2,5left Display I taught for a while. Onetime, I was stopped by theFort Worth police, because myhomework was too hard. Truestory. Vim 251
  • 252. 252 25 ex command:runtime macros/justify.vim visual " j" Visual " j" "gf": Display$VIMRUNTIME/macros/justify.vim. ex command:%!fmt*25.3* 8 1 Displaythe first linethe second line autoindent ex command:set autoindent 1 252
  • 253. 253 25 ">" ">>" shiftwidth 8. ">>" 4 ex command:set shiftwidth=4 ">>" Displaythe first line the second line 1 "4>>" 4 4 shiftwidth 4 <Tab> 8 softtabstop ex command:set softtabstop=4 4 4 8 ( 7 ). ( expandtab ) : tabstop 4 tabstop 8 tabstop 8 3 Vim 8 tabstop 3 Vim 1 253
  • 254. 254 25 Vim tabstop ":retab" ex command:set tabstop=3:retab 8 ":retab" tabstop 8 ":retab" "t"*25.4* Vim wrap Vim GUI Vim ex command:set guioptions+=b Vim 1 1 Vim GUI Bram 254
  • 255. 255 25 Listzh4zh 4zHzezl4zl 4zLzs "which" "w" "current window" "window" Display |<-- current window -->| some long text, part of which is visible in the windowze |<-- window -->|zH |<-- window -->|4zh |<-- window -->|zh |<-- window -->|zl |<-- window -->|4zl |<-- window -->|zL |<-- window -->|zs |<-- window -->| wrap Listg0g^gmg$ |<-- window -->|some long text, part of which is visible g0 g^ gm g$ 255
  • 256. 256 25word *edit-no-break* nowrap wrap wrap linebreak Vim linebreak Display+---------------------------------+|letter generation program for a b||ank. They wanted to send out a s||pecial, personalized letter to th||eir richest 1000 customers. Unfo||rtunately for the programmer, he |+---------------------------------+ ex command:set linebreak Display+---------------------------------+|letter generation program for a ||bank. They wanted to send out a ||special, personalized letter to ||their richest 1000 customers. ||Unfortunately for the programmer,|+---------------------------------+ : breakat showbreak 256
  • 257. 257 25 textwidth 0 "j" "k" 1 1 "gj" "gk" "j" "k" ex command:map <Up> gk:map <Down> gj MS-Word ex command:g/./,/^$/join ex command:g/./,/^$/ ( )join ":join" 30 8 1 257
  • 258. 258 25 Display+----------------------------------+|A letter generation program ||for a bank. They wanted to ||send out a special, ||personalized letter. || ||To their richest 1000 ||customers. Unfortunately for ||the programmer, |+----------------------------------+ Display+----------------------------------+|A letter generation program for a ||bank. They wanted to send out a s||pecial, personalized letter. ||To their richest 1000 customers. ||Unfortunately for the programmer, |+----------------------------------+ ex command:g/S/,/^s*$/join*25.5* Displaynice table test 1 test 2 test 3input A 0.534input B 0.913 258
  • 259. 259 25 3 "A", ex commandset virtualedit=all " " normal mode command/test 3 "j" "0.693" Displaynice table test 1 test 2 test 3input A 0.534 0.693input B 0.913 Vim "Bj" "B" "j" : Vim "test 1" 3 7 1. "/test 3". 2. CTRL-V . 3. :"2j" " " "test 3" "input B" . 259
  • 260. 260 25 4. "9l". 5. "y" . 6. "test 1" . 7. "P" . Displaynice table test 3 test 1 test 2 test 3input A 0.693 0.534 0.693input B 0.913 "test 1" "test 3" ex command:set virtualedit= virtualedit "rx" Displayinp 0.693 0.534 0.693 | rx | Vinpx0.693 0.534 0.693 "gr" 260
  • 261. 261 25 Displayinp 0.693 0.534 0.693 | grx | Vinpx 0.693 0.534 0.693 "gr" "x" "R" replace ( |04.9|) Displayinp 0 0.534 0.693 | R0.786 | Vinp 0.78634 0.693 "gR" Displayinp 0 0.534 0.693 |gR0.786 | Vinp 0.786 0.534 0.693 |usr 26.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 261
  • 262. 262 26*usr 26.txt* Vim 7.0 . 2006 04 24 VIM --- Bram Moolenaar --- 8 B|26.1| Visual|26.2||26.3||26.4| shell Vim |usr 27.txt| Search commands and patterns |usr 25.txt| Editing formatted text |usr toc.txt|*26.1* Visual Visual "gv" Visual "2001" "2002", "2000" "2001": DisplayThe financial results for 2001 are betterthan for 2000. The income increased by 50%,even though 2001 had more rain than 2000. 2000 2001income 45,403 66,234 262
  • 263. 263 26 "2001" "2002" Visual ex command:s/2001/2002/g "gv" ":s/2000/2001/g"*26.2* 1 CTRL-A 1 normal mode command/19[0-9][0-9]|20[0-9][0-9] CTRL-A 1: DisplayThe financial results for 2002 are betterthan for 2000. The income increased by 50%,even though 2001 had more rain than 2000. 2000 2001income 45,403 66,234 "n" "." CTRL-A("." ) "n" "." hlsearch 1 CTRL-A 1. item four 1 ::3,5s/19[0-9][0-9]|20[0-9][0-9]/=((submatch(0)+1)/g) 263
  • 264. 264 26 2. item five 3. item six "1" normal mode command3 CTRL-A "1" "4" "." Display006 foo bar007 foo bar CTRL-A Display007 foo bar010 foo bar 7 1 10 Vim "007" 0 C 8 ex command:set nrformats-=octal CTRL-X*26.3* C "x cnt" "x counter" ex command:args *.c 264
  • 265. 265 26 C ex command:argdo %s/<x_cnt>/x_counter/ge | update ":argdo" "%s" "<x cnt>" "x cnt" "<" ">" "px cnt" "x cnt2" x cnt "g" "x cnt" "e" "x cnt" ":argdo" "|" "update" "x cnt" "x counter" ":argdo" ":windo" ":bufdo" ":buffers" ( ":ls")*26.4* shell Vim "-person-" "Jones" shell Vim Normal Normal Ex .("Ex command" / ) Ex ex command%s/-person-/Jones/gwrite tempfilequit 265
  • 266. 266 26 "change.vim" Vim: shell commandfor file in *.txt; do vim -e -s $file < change.vim lpr -r tempfiledone shell for-done $file Ex (-e ) Vim $file "change.vim" -s Vim : "lpr -r tempfile" "tempfile" (-r ). Vim Vim "-" shell commandls | vim - "ls" "-S" shell commandproducer | vim -S change.vim -Normal Normal shell commandvim -s script file.txt ... 266
  • 267. 267 26 : "-s" "-e" "script" Normal "-e" silent( ) "scrip" Vim Normal shell commandvim -w script file.txt ... "script" "-w" "-W" |usr 27.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 267
  • 268. 268 27*usr 27.txt* Vim 7.0 . 2007 11 10 VIM --- Bram Moolenaar 1 3 Vim |pattern||27.1||27.2||27.3||27.4||27.5||27.6||27.7||27.8||27.9| |usr 28.txt| |usr 26.txt| |usr toc.txt|*27.1* Vim "include","INCLUDE" "Include" word Vim ignorecase 1 vim regular expresion, pattern / 268
  • 269. 269 27 ex command:set ignorecase "include" "Include","INCLUDE" "InClUDe" ( hlsearch ). ex command:set noignorecase "INCLUDE" "include". smartcase ex command:set ignorecase smartcase word Listpattern matchesword word, Word, WORD, WoRd, etc.Word WordWORD WORDWoRd WoRd "c" "C" ignorecase smartcase "c" "C" Vim ListCword wordCWord Wordcword word, Word, WORD, WoRd, etc.cWord word, Word, WORD, WoRd, etc. 269
  • 270. 270 27 "c" "C" 1 ignorecase smartcase : "" magic magic magic, : Unix CTRL-C, MS-DOS MS-Windows CTRL-Break*27.2* "n" Vim Displaysearch hit BOTTOM, continuing at TOP "?" Displaysearch hit TOP, continuing at BOTTOM ruler ex command:set ruler 1 270
  • 271. 271 27 Vim ( ). Display101,29 84% ex command:set nowrapscan DisplayE385: search hit BOTTOM without match for: forever "gg" "?" DisplayE384: search hit TOP without match for: forever*27.3* Vim "/" / normal mode command/default/2 271
  • 272. 272 27 "default" 2 Vim 1 "default" 1 2 "an offset" .. N "e" normal mode command/const/e "const" "t" ex command/const/e+1 ex command/const/e-1 "const" "s" "b" ex command/const/b+2 "n" 1 " " " " 272
  • 273. 273 27 ex command/that//e ex command/that/e ex command/ "n" ex command// "?" "?" ex command?const?e-2 "b" "e" "?" ex command/const/-2 273
  • 274. 274 27 "const" 2 "n" Vim "const" "const" "const" 2 Vim*27.4* "*" ex command/a* "a", "aa", "aaa" ""( ) 0 "*" "ab*" "a","ab", "abb", "abbb" "(" ")" ex command/(ab)* "ab", "abab", "ababab" "". "+" 1 normal mode command/ab+ "ab", "abb", "abbb" "b" "a" "=" 274
  • 275. 275 27 normal mode command/folders= "folder" "folders" "{n,m}" "n" "m" "n" "m" |inclusive| normal mode command/ab{3,5} "abbb", "abbbb" "abbbbb". "n" 0 "m" ",m" "n" List{,4} 0, 1, 2, 3 4{3,} 3, 4, 5{0,1} 0 1 ={0,} 0 *{1,} 1 +{3} 3 1 " " "{-n,m}" "{n,m}" normal mode command/ab{-1,3} 1 Jeffrey E.F. Friedl <<Mastering Regular Expressions>> --- greedy( ) lazy( ) perl 275
  • 276. 276 27 "abbb" "ab" b "n" "m" "{-}" 0 0 normal mode command/a.{-}b "axbxb" "axb" normal mode command/a.*b "axbxb"*27.5* " " "|" normal mode command/foo|bar "foo" "bar" normal mode command/one|two|three "one", "two" "three" "(" ")" normal mode command/(foo|bar)+ "foo", "foobar", "foofoo", "barfoobar" normal mode command/end(if|while|for) 276
  • 277. 277 27 "endif", "endwhile" "endfor" "&" normal mode command/forever&... "forever" "for" "fortuin" 1 "for"*27.6* "a" "b" "c" "/a|b|c" "a" "z" 26 .. normal mode command/[a-z] [] normal mode command/[0123456789abcdef] ASCII 1 "0-3" "0123". "w-z" "wxyz" normal mode command/[0-9a-f] "-" [] ( ): 1 "fortuin" forever forever&... forever 3 for for /forever&.../e for r &, |/&| 277
  • 278. 278 27 Liste <Esc>t <Tab>r <CR>b <BS> [] |/[]| [] "^" [] List/"[^"]*" " [^"] * " "foo" "3!x" Vim Vim normal mode command/a "/[a-zA-Z]"1 1 <unicell@gmail.com> 278
  • 279. 279 27 Listd [0-9]D [^0-9]x [0-9a-fA-F]X [^0-9a-fA-F]s [ ] (<Tab> <Space>)S [^ ] ( <Tab> <Space> )l [a-z]L [^a-z]u [A-Z]U [^A-Z] : [] a [] "[dl]" "(d|l)" OK a Vim |/s|*27.7* normal mode command/f+ "f" MS-Windows Unix isfname Unix 279
  • 280. 280 27 ex command:set isfnameisfname=@,48-57,/,.,-,_,+,,,#,$,%,~,= "f" : Unix a isfname Vim isfname b a b Unix 0 / 1 : Listi isidentI ik iskeywordK kp isprintP pf isfnameF f*27.8* Vim 2 1 2 MS-DOS MS-Windows " "(ASCII 13) " "(ASCII 10) Unix " "(ASCII 10) Mactonish " "(ASCII 10) " "(ASCII 13) 280
  • 281. 281 27 "n": normal mode command/thenword "the" "word" "the word" " s" normal mode command/the_sword 1 normal mode command/the_s+word "the " " word" "s" " s" "a" " a" " " " ." : " .*" " []" 2 : normal mode command/"_[^"]*"*27.9* 1 : 2 [...n] 281
  • 282. 282 27 "1MGU103" 3 3 normal mode command/duuuddd normal mode command/du{3}d{3} [] normal mode command/[0-9][A-Z]{3}[0-9]{3} 1 C ( ) normal mode command/<hw*> "<" ">" "h" "[A-Za-z ]", "w" 2 ".[0-9A-Za-z]" 1 ;-). 2 ASCII 9 A, Z a "[0-z]" 282
  • 283. 283 27 : "<" ">" iskeyword "-" "ident-" a w@<!hw*w@! b "w" /@<! /@!. a iskeyword "ident-a" "<hw*" "ident" w "-" "ident-" "-" keyword ">" b ... ... ... ..., <unicell@gmail.com> . |usr 28.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 283
  • 284. 284 28*usr 28.txt* Vim 7.0 . 2008 06 14 VIM --- Bram Moolenaar|28.1| ?|28.2||28.3||28.4||28.5||28.6||28.7||28.8||28.9||28.10| ? |usr 29.txt| |usr 27.txt| |usr toc.txt|*28.1* ? 284
  • 285. 285 28 Display+------------------------+| line 1 || line 2 || line 3 ||_______________________ | ________________________ / folded lines //________________________/| line 12 || line 13 || line 14 |+------------------------+*28.2* normal mode commandzfap |zf| |ap| |zf| 1 |zf| Visual normal mode commandzo 1 zf 285
  • 286. 286 28 normal mode commandzc "z" "z" normal mode commandzfzozc "zo" normal mode commandzr R-educe1 normal mode commandzm "zr" "zm" normal mode commandzR normal mode commandzM 1 286
  • 287. 287 28 |zn| |zN| |zi| • • • |zi| • |zi| |fold-manual|*28.3* "j" "k" foldmethod "dd" "p" Visual • • "V" Visual • • "d" • "p" |zo| ex command:set foldcolumn=4 287
  • 288. 288 28 "+" "-" "|" "+" "-" "|" |zO| |zC| |zd| |zD| Insert "0" ( foldopen "hor" ).foldopen ex command:set foldopen=all ex command:set foldopen& ex command:set foldclose=all foldlevel. |zm| |zr|*28.4* 288
  • 289. 289 28 ( ) ex command:mkview viewoptions ex command:loadview 10 3 2 ex command:mkview 3:loadview 2 viewdir*28.5* |zf| Vim foldmethod ex command:set foldmethod=indent |zm| |zr| 289
  • 290. 290 28 DisplayThis line is not indented This line is indented once This line is indented twice This line is indented twice This line is indented onceThis line is not indented This line is indented once This line is indented once shiftwidth shiftwidth |zr| |zm| foldlevel ex command:set foldlevel=3 3 3 shiftwidth foldlevel 0 . |zM| foldlevel 0 |zR| foldlevel (A) . (B) |zo| |zc| . |zm| |zo| |zR| |zm| foldmethod "indent" |fold-indent| 290
  • 291. 291 28*28.6* ex command:set foldmethod=marker C code/* foobar () {{{ */int foobar(){ /* return a value {{{ */ return 42; /* }}} */}/* }}} */ code/* global variables {{{1 */int varA, varB;/* functions {{{1 *//* funcA() {{{2 */void funcA() {}/* funcB() {{{2 */void funcB() {}/* }}}1 */ 291
  • 292. 292 28 |fold-marker| *28.7* Vim Vim "help" "fold" Vim |fold-syntax| *28.8* e-mail ">" ex command:set foldmethod=expr:set foldexpr=strlen(substitute(substitute(getline(v:lnum),s,,"g"),[^>].*,,)) 292
  • 293. 293 28 Display> quoted text he wrote> quoted text he wrote> > double quoted text I wrote> > double quoted text I wrote foldexpr Listgetline(v:lnum)substitute(...,s,,g)substitute(...,[^>].*,,)) >strlen(...) > ":set" ex command:set foldexpr ex command:set foldexpr=<Tab> <Tab> Vim foldexpr foldexpr |fold-expr|*28.9* diff |vimdiff| ex command :setlocal diff foldmethod=diff scrollbind nowrap foldlevel=1 293
  • 294. 294 28 |fold-diff|*28.10* ? |:mkview| shiftwidth 1 "expr" |usr 29.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 1 294
  • 295. 295 29*usr 29.txt* Vim 7.0 . 2008 06 28 VIM --- Bram Moolenaar 1 Vim . Vim|29.1| tags|29.2||29.3||29.4||29.5| |usr 30.txt| |usr 28.txt| |usr toc.txt|*29.1* tags tag C C++ tag tags Vim tag -- C tags shell commandctags *.c 1 ... 295
  • 296. 296 29 "ctags" Unix ctags: URLhttp://ctags.sf.net Vim ex command:tag startlist "startlist" CTRL-] word tag C "write block" "write line" "write line" CTRL-] "write line" "write char". "write char" CTRL-] "write char" 296
  • 297. 297 29 code+-------------------------------------+|void write_block(char **s; int cnt) ||{ || int i; || for (i = 0; i < cnt; ++i) || write_line(s[i]); ||} | |+------|------------------------------+ | CTRL-]| | +----------------------------+ +->|void write_line(char *s) | |{ | | while (*s != 0) | | write_char(*s++); | |} | | +------|---------------------+ | CTRL-] | | +------------------------------------+ +->|void write_char(char c) | |{ | | putchar((int)(unsigned char)c); | |} | +------------------------------------+ ":tags" tag ex command:tags # TO tag FROM line in file/text 1 1 write_line 8 write_block.c 2 1 write_char 7 write_line.c CTRL-T tag "write char" "write line" CTRL-T 297
  • 298. 298 29 tag ex command:tag ":3tag" CTRL-T ( CTRL-]) ( CTRL-T) ":tags" 1 ":tag" ":tag" ":split". Vim ex command:stag tagname tag: normal mode commandCTRL-W ] tags tags Vim tags 2 tags tags tags ex command:set tags=./tags,./../tags,./*/tags 1 2 298
  • 299. 299 29 Vim tags tags tags tags "~/proj/src" "~/proj/sub/tags" tags Vim ex command:set tags=~/proj/**/tags tags Vim tags 1 tags ctags shell commandcd ~/projctags -R . ctags C C++ Eiffel Vim ctags Vim tags ex command:set tags=~/proj/tags tag ( ),":tag" tag 1 PC Linux Xwindows 299
  • 300. 300 29 ex command:tnext tag ex command:tselect tagname Vim Display # pri kind tag file 1 F f mch_init os_amiga.c mch_init() 2 F f mch_init os_mac.c mch_init() 3 F f mch_init os_msdos.c mch_init(void) 4 F f mch_init os_riscos.c mch_init()Enter nr of choice (<CR> to abort): ( ) tag ex command:tfirst go to first match:[count]tprevious go to [count] previous match:[count]tnext go to [count] next match:tlast go to last match [count] 1.tag ... tag 300
  • 301. 301 29 ex command:tag write_<Tab> Vim tag tag tag Vim tag. 1 "block" tag : ex command:tag /block <Tab>. Vim "block" tag "/" Vim tag tag "write " ex command:tselect /^write_ "^" tag "write " write tag "$" Vim tagtags CTRL-] word tag tag ( ctags): shell commandctags --c-types=f -f functions *.c Vim shell commandvim:vsplit functions 1 301
  • 302. 302 29 ":setlocal ts=99" ex command:nnoremap <buffer> <CR> 0ye<C-W>w:tag <C-R>"<CR> Vim ignorecase tag tagsearch Vim tags tag tag tag. taglength Vim tag ================ --- ================ code#include <stdio.h>int very_long_variable_1;int very_long_variable_2;int very_long_variable_3;int very_long_variable_4;int main(){ very_long_variable_4 = very_long_variable_1 * very_long_variable_2;} 4 20 taglength 10 ex command:tag very_long_variable_4 4 tag 1 very long variable 1 tag 10 "very long " ( gvim ): 302
  • 303. 303 29 Display tag: 1/4 ================ --- ================ SNiFF+ Vim |sniff|.SNiFF Cscope |cscope|*29.2* -- tag "write char" ex command:ptag write_char Vim "write char" CTRL-W k normal mode commandCTRL-W } Vim word tag |CursorHold-example| ex command:pclose ":pedit" 303
  • 304. 304 29 ex command:pedit defs.h ":psearch" include tags ex command:psearch popen "stdio.h" popen() DisplayFILE *popen __P((const char *, const char *)); previewheight*29.3* Vim C code#ifdef USE_POPEN fd = popen("ls", "r")#else fd = fopen("tmp", "w")#endif "#ifdef" %. Vim "#else". % "#endif" % "#ifdef" Vim "#endif" 304
  • 305. 305 29 "#if"-"#endif" 1 : normal mode command[# "#if" "#ifdef" Vim "#else" "#endif" normal mode command]# "#if"-"#endif" code#if defined(HAS_INC_H) a = a + inc();# ifdef USE_THEME a += 3;# endif set_width(a); "[#" "#ifdef"-"endif" C {} "[[" "][" "{" "}" "[{" "]}" 1 "#if" 305
  • 306. 306 29 code function(int a) +-> { | if (a) | +-> {[[ | | for (;;) --+ | | +-> { | | [{ | | foo(32); | --+ | | [{ | if (bar(a)) --+ | ]} | +-- | +-- break; | ]} | | | } <-+ | | ][ +-- foobar(a) | | } <-+ | } <-+ 1 C++ Java {} {} "[m" "]m" 2 "[]" "]]" "}" 1 C#, Eiffel 2 Java C# C++ C 306
  • 307. 307 29 code int func1(void) { return 1; +----------> } | [] | int func2(void) | +-> { | [[ | if (flag)start +-- +-- return flag; | ][ | return 2; | +-> } ]] | | int func3(void) +----------> { return 3; } "%" (), {} [] "[(" "])" "[ "]"", () {} code [( <-------------------------------- <-------if (a == b && (c == d || (e > f)) && x > y) --------------> --------------------------------> > ]) "[/" "]/" /* - */ 307
  • 308. 308 29 code +-> +-> /* | [/ | * A comment about --+[/ | +-- * wonderful life. | ]/ | */ <-+ | +-- foo = bar * 3; --+ | ]/ /* a short comment */ <-+*29.4* C "int" "unsigned" "[I" "column" normal mode command[I Vim 1 include include include Displaystructs.h 1: 29 unsigned column; /* column number */ tags include tags tags. "[I" Vim include include C C++ include 1 C/C++ #include stdio.h 308
  • 309. 309 29 Vim path include include ex command:checkpath include Display--- Included files not found in path ---<io.h>vim.h --> <functions.h> <clib/exec_protos.h> "io.h" "vim.h" ":checkpath" "vim.h" include "functions.h" "clib/exec protos.h" : Vim "#ifdef" "#include" "#if a NEVER" a C/C++ #if 0 path Makefile "-I" "-I/usr/local/X11" ex command:set path+=/usr/local/X11 "*" ex command:set path+=/usr/*/include 309
  • 310. 310 29 "/usr/local/include" "/usr/X11/include" "**" Vim ex command:set path+=/projects/invent/**/include include List/projects/invent/include/projects/invent/main/include/projects/invent/main/os/includeetc. path include ex command:checkpath! include include include Vim "(Already listed)" include "[I" normal mode command[<Tab> "[ CTRL-I", CTRL-I <Tab> "[I" 310
  • 311. 311 29 normal mode command3[<Tab> 3 CTRL-O List[i]I]i "[I" "#define" normal mode command[D include define "[D" C C++ "[D" List[d]D]d*29.5* "[I" include normal mode commandgD goto Definition ( "counter" ): 311
  • 312. 312 29 code +-> static int counter = 0; | | int get_counter(void)gD | { | ++counter; +-- return counter; } normal mode commandgd word "{" ( "idx" ): code int find_entry(char *name) { +-> int idx; |gd | for (idx = 0; idx < table_len; ++idx) | if (strcmp(table[idx].name, name) == 0) +-- return idx; } |usr 30.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 312
  • 313. 313 30*usr 30.txt* Vim 7.0 . 2007 11 10 VIM --- Bram Moolenaar Vim|30.1||30.2| C|30.3||30.4||30.5||30.6| |usr 31.txt| GUI |usr 29.txt| |usr toc.txt|*30.1* Vim "quickfix" Vim "make"( ) ex command:make {arguments} Vim 313
  • 314. 314 30 ":make" ( :make ) ":make" Display:!make | &tee /tmp/vim215953.errgcc -g -Wall -o prog main.c sub.cmain.c: In function main:main.c:6: too many arguments to function do_submain.c: At top level:main.c:10: parse error before }make: *** [prog] Error 12 returned"main.c" 11L, 111C(3 of 6): too many arguments to function do_subHit ENTER or type command to continue "main.c" <Enter> , Vim "main.c" 6 Vim code +---------------------------------------------------+ |int main() | |{ | | int i=3; |cursor -> | do_sub("foo"); | | ++i; | | return (0); | |} | |} | | ~ | |(3 of 12): too many arguments to function do_sub | +---------------------------------------------------+ ex command:cnext 314
  • 315. 315 30 Vim 10 "}" Vim ex command:cc ":clist" Display:clist3 main.c: 6:too many arguments to function do_sub5 main.c: 10:parse error before } Vim ":clist" "!" Display:clist!1 gcc -g -Wall -o prog main.c sub.c2 main.c: In function main:3 main.c:6: too many arguments to function do_sub4 main.c: At top level:5 main.c:10: parse error before }6 make: *** [prog] Error 1 Vim ex command:cprevious List:cfirst:clast:cc 3 3 315
  • 316. 316 30 makeprg ":make" "make" Visual C++ 1 "nmake" : ex command:set makeprg=nmake ex command:set makeprg=nmake -f project.mak 2 Vim % ex command:set makeprg=make % main.c ":make" ex commandmake main.c :r ex command:set makeprg=make %:r.o ex commandmake main.o |filename-modifiers| 1 "nmake" Visual C++ make 2 :Vim 316
  • 317. 317 30 ":make" 1 " " 2 ":make" Vim ":make" ":make" ex command:colder ":clist" ":cc {nr}" warning ex command:cnewer Vim 10 Vim errorformat |errorformat| makeprg errorformat Vim Microsoft Visual C++ ex command:compiler msvc 1 Warning Error 2 warning, error, fatal error. warning error fatalerror error 317
  • 318. 318 30 "msvc" Vim |write-compile-plugin| ":make" Vim shell ":make" makeef shellpipe shellquote shellxquote ":make" ex command:cfile {filename} ":make"*30.2* C Vim C C Java C++ , cindent Vim C C shiftwidth 4 ":set" ex command:set cindent shiftwidth=4 "if (x)" List if (flag) ---> do_the_work(); <-- if (other_flag) { ---> do_file(); do_some_more(); <-- } 318
  • 319. 319 30 Vim "}" Vim } } "%" ) ; "=" normal mode command== Visual "=" "a{" -- {} normal mode command=a{ normal mode commandgg=G Vim Vim 90% cinoptions 319
  • 320. 320 30 cinoptions Vim codeif (flag) { i = 8; j = 0; } ex command:set cinoptions+={2 |cinoptions-value|*30.3* C cindent ex command:filetype indent on C cindent Vim Vim ex command:filetype indent off 320
  • 321. 321 30 ex command:let b:did_indent = 1 List{directory}/indent/{filetype}.vim {filetype} "cpp" "java" Vim ex command:set filetype Displayfiletype=help {filetype} "help" {directory} ex commandset runtimepath Displayruntimepath=~/.vim,/usr/local/share/vim/vim60/runtime,~/.vim/after {directory} "~/.vim" List~/.vim/indent/help.vim |indenting-expression| 321
  • 322. 322 30*30.4* autoindent smartindent smartindent cindent autoindent smartindent } cinwords # 1 1 autoindent smartindent Insert CTRL-D CTRL-T2 shell shell commandif test -n a; then echo a echo "-------"fi ex command:set autoindent shiftwidth=3 codeif test -n a; thenecho CTRL-T 1 C/C++ 2 / 322
  • 323. 323 30 codeif test -n a; then echo Insert CTRL-T shiftwidth 1 ...: codeif test -n a; then echo a echo "-------" fi CTRL-D 4 shiftwidth Normal ">>" "<<" 2 / ">" "<" 3 3 normal mode command>i{ 4 {} . ">a{" { } 5 "printf" : 1 <Tab> " " ! 2 :Vim 3 :Vim * 4 shiftwidth 5 ">a{" ">i{" 323
  • 324. 324 30 Display ">i{" ">a{"if (flag) if (flag) if (flag){ { {printf("yes"); printf("yes"); printf("yes");flag = 0; flag = 0; flag = 0;} } }*30.5* tabstop 8 8 8 tabstop 8 ( 8 |25.3| ). 8 1 4 8 4 1. 8 8 . 2. . Vim Vim softtabstop Vim 324
  • 325. 325 30 <Tab> softtabstop 4 ex command:set softtabstop=4 4 Vim 4 ( 8 ). Vim softtabstop "." "------->" Display<Tab> ....<Tab><Tab> -------><Tab><Tab><Tab> ------->....<Tab><Tab><Tab><BS> -------><Tab><Tab><Tab><BS><BS> .... smarttab Vim 1 shiftwidth <Tab> softtabstop expandtab ex command:set expandtab 1 shiftwidth tabstop 325
  • 326. 326 30 1 <Tab> 8 CTRL-D ( ) expandtab ":retab" ex command:set expandtab:%retab Vim 2 !: ex command:%retab! normal mode command/"[^"t]*t[^"]*" <Tab> "t" ex command:set noexpandtab:%retab!*30.6* 1 : boolean 2 ! 326
  • 327. 327 30 Vim Vim code/* * This is a test * of the text formatting. */ normal mode commandgq]/ "gq" "]/" code/* * This is a test of the text formatting. */ Vim Visual "gq" "o" code/* * This is a test of the text formatting. * */ Vim textwidth Vim 327
  • 328. 328 30 code/* * This is a test of the text formatting. * Typing a lot of text here will make Vim * break */ formatoptions Listr Inserto Normal "o" "O"c textwidth |fo-table| comments Vim C++ //, Makefiles #, Vim " Vim C++ ex command:set comments=:// Vim comments Display{flags}:{text} {flags} e-mail ">" "!" ex command:set comments=n:>,n:! 328
  • 329. 329 30 ">" "!" "n" ">" Display> ! Did you see that site?> ! It looks really great.> I dont like it. The> colors are terrible.What is the URL of thatsite? textwidth Visual 1 "gq" : Display> ! Did you see that site? It looks really great.> I dont like it. The colors are terrible.What is the URL of that site? Vim 2 "I" 1 1 ">!" 2 ">" Vim C "/*" "*" "*/" comments ex command:set comments=s1:/*,mb:*,ex:*/ "s1:/*" "s" start "/*" "1" Vim "mb:*" "m" middle, "b" "*" Vim "*pointer" 1 gq indent, comments, textwidth 329
  • 330. 330 30 :"ex:*/", "e" (end)1 "x" Vim / |format-comments| |usr 31.txt| GUI |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 1 330
  • 331. 331 31 GUI*usr 31.txt* Vim 7.0 . 2007 05 08 VIM --- Bram Moolenaar GUI Vim GUI|31.1||31.2||31.3||31.4| Vim|31.5| |usr 32.txt| |usr 30.txt| |usr toc.txt|*31.1* File/Open... Window/Split File/Open... Vim "browse": ex command:browse split ":split" 331
  • 332. 332 31 GUI / / ex command:browse split /etc "/etc" 1 ":browse" ":browse split" "/usr/local/share" "/usr/local/share" browsedir Vim Listlast ( )buffercurrent "/usr" "/usr/local/share/readme" ex command:set browsedir=buffer:browse edit "/usr/local/share" ex command:set browsedir=current:browse edit "/usr" : Vim 1 vertical hide 332
  • 333. 333 31 GUI GUI ":browse" |netrw-browse|*31.2* Vim Vim ! ! Vim "OK" "Cancel" Vim ex command:confirm edit foo.txt Vim Display+-----------------------------------+| || ? Save changes to "bar.txt"? || || YES NO CANCEL |+-----------------------------------+ "YES" "NO" "CANCEL" ":browse" ":confirm" 1 ex command:confirm browse edit 1 ":confirm" Vim ":confirm echo asdf" ":confirm q" 333
  • 334. 334 31 GUI : <Tab> GUI ":confirm" Display:confirm edit main.cSave changes to "Untitled"?[Y]es, (N)o, (C)ancel:*31.3* Vim <Alt> <A-w>(<Alt> w) Window Window "split" p <Alt> p. <Alt> <Right> <Left> <Esc> 1 <Enter> <Alt> winaltkeys Vim <Alt> "menu" 1 334
  • 335. 335 31 GUI "no" <Alt> "yes" <Alt> 1*31.4* Vim Vim ex command:winpos GUI DisplayWindow position: X 272, Y 103 Vim 100 ex command:winpos 172 103 : Vim ex command:set lines columns lines / columns ex command:set lines=50:set columns=80 1 <A-F4> Vim 335
  • 336. 336 31 GUI Vim GUI X-Windows gvim shell commandgvim -geometry {width}x{height}+{x_offset}+{y_offset} {width} {height} {x offset} {y offset} shell commandgvim -geometry 80x25+100+300*31.5* gvim email e-mail gvim mail gvim gvim shell gvim gvim shell "-f" shell commandgvim -f file.txt "-f" foreground( ) Vim shell Vim GUI Unix Vim GUI ex command:gui 336
  • 337. 337 31 GUI Vim GUI "-f" GUI ":gui -f"GVIM gvim gvimrc Vim vimrc. gvimrc GUI lines ex command:set lines=55 ( xterm ). gvimrc vimrc Unix "~/.gvimrc", MS-Windows "$VIM/ gvimrc" $MYGVIMRC ex command:edit $MYGVIMRC gvimrc "-U" shell commandgvim -U thisrc ... gvim 1 gvimrc : shell commandgvim -U NONE ... |usr 32.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 1 vimrc vimrc -u NONE 337
  • 338. 338 32*usr 32.txt* Vim 7.0 . 2006 04 30 VIM --- Bram Moolenaar Vim|32.1||32.2||32.3| |usr 40.txt| |usr 31.txt| GUI |usr toc.txt|*32.1* |02.5| / / "one" " too" o w 1 2 338
  • 339. 339 32 Display one |change 1 |one too |change 2 |one two "one too" "one" "me" Display one | change 1 | one too / change 2 change 3 | |one two me too |u| "one" |CTRL-R| "one too" |CTRL-R| "me too" : 339
  • 340. 340 32*32.2* "one two" ex command:undo 2 "one two" 2 |:undo| "one" "not": Display one | change 1 | one too / change 2 change 3 | |one two me too |change 4 |not two "me too" |g-| |g-| Listme tooone twoone tooone |g+| 340
  • 341. 341 32 Listoneone tooone twome toonot two |:undo| |g-| |g+| |g-| |g+|*32.3* ex command:undolist Displaynumber changes time 3 2 16 seconds ago 4 3 5 seconds ago 4 "not two" 10 ex command:earlier 10s |:earlier| "m" "h" 341
  • 342. 342 32 ex command:earlier 10h |:later| ex command:later 1m |:earlier| "s", "m" "h" |usr 40.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 342
  • 343. 343 40*usr 40.txt* Vim 7.0 . 2006 06 21 VIM --- Bram Moolenaar : Vim|40.1||40.2||40.3| |usr 41.txt| Vim |usr 32.txt| |usr toc.txt|*40.1* |05.3| <F1> Vim ex command:map <F2> GoDate: <Esc>:read !date<CR>kJ 3 "G" "o" "Date: " <Esc> Insert 343
  • 344. 344 40 <> 1 copy &paste ":" Vim ":read !date" "date" <CR> ":read" DisplayDate:Fri Jun 15 12:54:34 CEST 2001 "kJ" |map-which-keys| ":map" Normal ":imap" Insert 2 Insert : ex command:imap <F2> <CR>Date: <Esc>:read !date<CR>kJ Normal <F2> Normal <F2> Insert Normal Insert "a" 1 Vim 2 MS-Windows :read !date<NUL date <NUL 1 <Enter> vim strftime :imap <F2><C-R>=strftime("%c")<CR> |strftime()| 344
  • 345. 345 40 List:map Normal, Visual and Operator-pending:vmap Visual:nmap Normal:omap Operator-pending:map! Insert and Command-line:imap Insert:cmap Command-line Operator-pending "d" "y" Vim Vim Vim Operator-pending "dw" "w" Operator-pending <F7> d<F7> C ( {} ) y<F7> yank <F7> ex command:omap <F7> a{ <F7> Operator-pending 1 "a{" { ":map"( ) 2 : List _g :call MyGrep(1)<CR>v <F2> :s/^/> /<CR>:noh<CR>``n <F2> :.,$s/^/> /<CR>:noh<CR>`` <xHome> <Home> <xEnd> <End> 1 { :-) 2 Vim 345
  • 346. 346 40 "n" Normal "i" Insert 1 ":map" Normal Visual <> Vim ( Vim ) <Esc> ASCII 27 ESC 5 2 Vim <F2> ex command:map <F2> G<F3>:imap <F2> <Esc><F3>:map <F3> oDate: <Esc>:read !date<CR>kJ Normal <F2> <F3>.Insert <F2> Insert <F3> <F3> Ex "Q" ( Vim ): ex command:map Q gq Ex "gQ" Q Ex ex command:map gQ Q 1 Visual "v" "V" CTR-V Visual 2 remapping re nest-mapping :map <C-K>j<C-K> <C-K> <C-K> j <C-K> :noremap <C-K> j<C-K> j <C-K> <C-K> VIM <C-K> Vim normal 346
  • 347. 347 40 "gQ" "Q" "Q" "gq" "gQ" "gq" Ex ":noremap" ex command:noremap gQ Q Vim "Q" List:noremap Normal, Visual and Operator-pending:vnoremap Visual:nnoremap Normal:onoremap Operator-pending:noremap! Insert and Command-line:inoremap Insert:cnoremap Command-line "vim *.txt" Vim ex command:map ,, :s/5.1/5.2/<CR>:wnext<CR>,, ",," "5.1" "5.2" ":wnext" ",," "5.1" "5.1" ":wnext" CTRL-C ( MS-Windows CTRL-Break). 347
  • 348. 348 40 ":unmap" 1 : List:unmap Normal, Visual and Operator-pending:vunmap Visual:nunmap Normal:ounmap Operator-pending:unmap! Insert and Command-line:iunmap Insert:cunmap Command-line Normal Operator-pending Visual 2 Visual ex command:map <C-A> /---><CR>:vunmap <C-A> "<C-A>" CTRL-A 3 |:mapclear| ":map" | | | <Bar> ex command:map <F8> :write <Bar> !checkin %<CR> ":unamp" ":unmap" 1 : mapping 2 Operator-pending Normal 3 348
  • 349. 349 40 ex command:unmap a | unmap b:unmap a| unmap b "a " <Space> ex command:map <Space> W word1 " | ex command:map <Space> W| " Use spacebar to move forward a word Insert Vim word 2 showcmd Vim ex command:imap aa foo:imap aaa bar 1 Vim WORD W w word S 2 vim " " " " " " " ", " " " " 349
  • 350. 350 40 "aa", Vim 3 "a" "bar" 1 "foo" ... <script> |:map-script| <buffer> |:map-buffer| <unique> |:map-unique| <Nop> <F7> ex command:map <F7> <Nop>| map! <F7> <Nop> <Nop>*40.2* Vim Vim 2 ":command" ex command :command DeleteFirst 1delete 1 3 a, Vim Vim ":abbr aatee" a Vim a a Vim Vim Vim Vim |mapping-typing| 2 ":command" 350
  • 351. 351 40 ":DeleteFirst" Vim ":1delete"-- : ":X", ":Next" ":Print" ex command:command Vim -nargs :DeleteFirst ex command:command -nargs=0 DeleteFirst 1delete "command" "-nargs=0" -nargs List-nargs=0-nargs=1 1-nargs=*-nargs=? 0 1-nargs=+ 1 <args> ex command:command -nargs=+ Say :echo "<args>" 351
  • 352. 352 40 ex command:Say Hello World Vim "Hello World" ex command:Say he said "hello" <q-args> ex command:command -nargs=+ Say :echo <q-args> ":Say" ex command:echo "he said "hello"" <f-args> <args> ex command:command -nargs=* DoIt :call AFunction(<f-args>):DoIt a b c ex command:call AFunction("a", "b", "c") Vim -range List-range-range=%-range={count} {count} 352
  • 353. 353 40 -range <line1> <line2> SaveIt "save file" ex command:command -range=% SaveIt :<line1>,<line2>write! save_file-count={number} {number} <count>-bang <bang> !-register <reg> <register>-complete={type} |:command-completion|-bar | "-buffer . <lt> < < command !: ex command:command -nargs=+ Say :echo "<args>":command! -nargs=+ Say :echo <q-args> ":delcommand" ex command:delcommand SaveIt 353
  • 354. 354 40 ex command:comclear |user-commands|*40.3* Vim |gzip| plugin ex command:function DateInsert(): $delete: read !date:endfunction ex command:autocmd FileWritePre * call DateInsert() "FileWritePre" "*" ":write" Vim FileWritePre ":write" :autocmd 354
  • 355. 355 40 ex command:autocmd [group] {events} {file_pattern} [nested] {command} [group] ( ). {events} ( ). {file pattern} "*.txt" ".txt" [nested] {command} BufReadPost Vim "*.gsm" GNU ex command:autocmd BufReadPost *.gsm set filetype=asm Vim filetype FileType ex command:autocmd Filetype text source ~/.vim/abbrevs.vim Vim ex command:autocmd BufNewFile *.[ch] 0read ~/skeletons/skel.c |autocmd-events| {file pattern} "*.c,*.h" ".c" ".h" 355
  • 356. 356 40 List*?[abc] a b c.a{b,c} ab ac (/)Vim "*.txt" "/home/biep/readme.txt". "/home/biep/*" "home/foo/*.txt" Vim ("/home/biep/readme.txt") ( "biep/readme.txt). : MS-Windows / {command} autocmd ! ex command:autocmd! FileWritePre * "*" "FileWritePre" 1 ex command:autocmd 1 : 356
  • 357. 357 40 :autocmd + BufNewFile ex command:autocmd BufNewFile "*.c" ex command:autocmd * *.c "*" cprograms ex command:autocmd cprograms {group} ":augroup" C ex command:augroup cprograms: autocmd BufReadPost *.c,*.h :set sw=4 sts=4: autocmd BufReadPost *.cpp :set sw=3 sts=3:augroup END ex command:autocmd cprograms BufReadPost *.c,*.h :set sw=4 sts=4:autocmd cprograms BufReadPost *.cpp :set sw=3 sts=3 "cporgrams" ex command:autocmd! cprograms 357
  • 358. 358 40 1 FileChangedShell autocmd "nested" ex command :autocmd FileChangedShell * nested edit ex command:autocmd BufReadPost *.new execute "doautocmd BufReadPost ".expand("<afile>:r") ".new" ":execute" 2 "tryout.c.new" ex command :doautocmd BufReadPost tryout.c expand() "<afile>" autocommand 3 ":r" ":doautocmd" ":doautoall" Normal Normal ":normal" ex command :autocmd BufReadPost *.log normal G 1 map remap chained autocmd recursive autocmd 2 shell perl eval 3 358
  • 359. 359 40 .log ":normal" "i" Insert <Esc> Insert "/" <CR>1 ":normal" Normal | ":normal" ":execute" ex command:autocmd BufReadPost *.chg execute "normal ONew entry:<Esc>" | 1read !date Vim ( ). |restore-position| eventignore 2 Vim Vim :set eventignore=WinEnter,WinLeave 3 : ex command:set eventignore=all eventignore 1 2 :VIM += -= 3 all NONE hi ctermfg=none . 359
  • 360. 360 40 ex command:set eventignore= |usr 41.txt| Vim |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 360
  • 361. 361 41 Vim*usr 41.txt* Vim 7.0 . 2008 06 21 VIM --- Bram Moolenaar Vim Vim Vim|41.1||41.2||41.3||41.4||41.5||41.6||41.7||41.8||41.9||41.10||41.11| plugin|41.12| plugin|41.13| plugin|41.14| plugin|41.15||41.16| Vim |usr 42.txt| |usr 40.txt| |usr toc.txt|*41.1* *vim-script-intro* *script* 361
  • 362. 362 41 Vim Vim Vim Vim ( Ex ). Vim Vim Vim Vim code:let i = 1:while i < 5: echo "count is" i: let i += 1:endwhile : ":" Vim Vim . : " @ Displaycount is 1count is 2count is 3count is 4 ":let" code:let {variable} = {expression} "i" 1. ":while" 362
  • 363. 363 41 Vim code:while {condition}: {statements}:endwhile ":while" ":endwhile" "i < 5" i 5 : CTRL-C ( MS-Windows CTRL-Break)":echo" "countis" i i 1 Displaycount is 1 ":let i += 1" ":let i = i + 1" i "i + 1" i 1. ex command:for i in range(1, 4): echo "count is" i:endfor :for range() "0x" "0X" "0x1f" 31 0 "017" 15 : 0 1 ":echo" 1 :echo 092 0 9 Vim :echo 011 9 363
  • 364. 364 41 Vim Display:echo 0x7f 036127 30 1 Display:echo 0x7f -03697 Display:echo 0x7f - 036*41.2* ASCII 2 : Displaycounter_aap3very_long_variable_name_with_underscoresFuncLengthLENGTH 3 "foo+bar", "6var". 1 2 Vim C/C++/Java "[a-zA-Z ][a-zA-Z0-9 ]*" 3 Vim 364
  • 365. 365 41 Vim ex command:let "count" "s:" code:let s:count = 1:while s:count < 5: source other.vim: let s:count += 1:endwhile "s:count" "other.vim" "other.vim" "s:count" "other.vim" |script-variable| Vim |internal-variables| Listb:namew:nameg:name ( )v:name Vim Vim ":let" ":unlet" ex command:unlet s:count "s:count" ! 365
  • 366. 366 41 Vim code:unlet! s:count code:if !exists("s:call_count"): let s:call_count = 0:endif:let s:call_count = s:call_count + 1:echo "called" s:call_count "times" "exists()" 1 ! code:if !exists(s:call_count) s:call count exists() ! true ! false false true "not" "if !exists()" "if not exists()". Vim 0 2 0 : Vim 0 :if "true" "true" 0 false! Vim 1 . 2 C 366
  • 367. 367 41 Vim ":let" |41.8| ex command:let name = "peter":echo namepeter " : ex command:let name = ""peter"":echo name"peter" 1 , 2 : code:let name = "peter":echo name"peter" 1 2 bash, perl, php... 367
  • 368. 368 41 Vim Listt <Tab>n <NL>r <CR>, <Enter>e <Esc>b <BS>, backspace" " , backslash<Esc> <Esc><C-W> CTRL-W "<name>" Vim |expr-quote|*41.3* Vim |expression-syntax| List$NAME&name Vim@ r Vim List:echo "The value of tabstop is" &ts:echo "Your home directory is" $HOME:if @ a > 5 &name 368
  • 369. 369 41 Vim List:let save_ic = &ic:set noic:/The Start/,$delete:let &ic = save_ic "The Start" ignorecase ( "C" |/C|.) Lista + ba - ba * ba / ba % b code:echo 10 + 5 * 220 code:echo (10 + 5) * 230 "." code:echo "foo" . "bar"foobar ":echo" C 369
  • 370. 370 41 Vim codea ? b : c "a" true "b" "c" code:let i = 4:echo i > 5 ? "i is big" : "i is small"i is small code(a) ? (b) : (c)*41.4* ":if" ":endif" code:if {condition} {statements}:endif {condition} true( 0 ) {statement} Vim Vim ":endif" ":else" code:if {condition} {statements}:else {statements}:endif {statement} ":elseif": 370
  • 371. 371 41 Vim code:if {condition} {statements}:elseif {condition} {statements}:endif ":else" "if" ":endif" Vim term code:if &term == "xterm": " Do stuff for xterm:elseif &term == "vt100": " Do stuff for a vt100 terminal:else: " Do something for other terminals:endif Lista == ba != ba > ba >= ba < ba <= b 1 0 code:if v:version >= 700: echo "congratulations":else: echo "you are using an old version, upgrade!":endif 371
  • 372. 372 41 Vim "v:version" Vim Vim 6.0 Vim 600. 6.1 Vim 601 ASCII 0 code:if 0 == "one": echo "yes":endif "yes" "one" 0 0 Lista =~ b a ba !~ b a b a b a b code:if str =~ " ": echo "str contains a space":endif:if str !~ .$: echo "str does not end in a full stop":endif ignorecase "#" 372
  • 373. 373 41 Vim "?" "==?" "!~#" |expr-==| ":while" ":while" ":endwhile" code:continue loop:break ":endwhile"; code:while counter < 40: call do_something(): if skip_flag: continue: endif: if finished_flag: break: endif: sleep 50m:endwhile 1 ":sleep" Vim "50m" 50 , :sleep 4 Vim 4 |41.8| |:for|*41.5* Vim ":execute" 1 1 1000 373
  • 374. 374 41 Vim ex command:execute "tag " . tag_name "." "tag " "tag name" "tag name" "get cmd" ex command:tag get_cmd ":execute" " ". ":normal" Normal Normal ex command:normal gg=G "=" ":normal" ":execute" ex command:execute "normal " . normal_commands "normal commands" Normal ":normal" Vim ex command:execute "normal Inew text <Esc>" "new text" 1 2 <ESC>"<Esc>" <Esc> eval() 1 <unicell@gmail.com> <Esc> , ! 2 : <Esc> ASCII 27 Vim ^[ COPY & PASTE ^[ ^ [ 374
  • 375. 375 41 Vim ex command:let optname = "path":let optval = eval(& . optname)"path" & eval "&path" path ex command:exe let optval = & . optname*41.6* Vim |functions| ":call" ex command:call search("Date: ", "W") "Date: " "W" search() search() "W" ex command:let line = getline("."):let repl = substitute(line, a, "*", "g"):call setline(".", repl) getline() "." substitute() ":substitute" 375
  • 376. 376 41 Vim setline() substitute() ex command:substitute/a/*/g substitute() *function-list* |functions| CTRL-] 376
  • 377. 377 41 Vim Listchar2nr() ASCIInr2char() ASCIIstr2nr()str2float()printf() %escape() shellescape() shellfnameescape() Vimtr()strtrans() atolower()toupper()match()matchend() match()matchstr() matchmatchlist() matchstrstridx()strridx()strlen()substitute()submatch() ":substitute" bstrpart()expand()iconv()byteidx()repeat()eval()a ASCII 9 TAB ^Ib () 377
  • 378. 378 41 Vim Listget()len()empty()insert()add()extend()remove()copy()deepcopy()filter()map()sort()reverse()split()join()range()string()call()index()max()min()count()repeat() 378
  • 379. 379 41 Vim Listget()len()has_key()empty()remove()extend()filter()map()keys()values()items() -copy()deepcopy()string()max()min()count() : Listfloat2nr()abs() ( )round() aceil()floor()trunc()log10() 10pow() x ysqrt()sin() sinecos() cosineatan() arc tangenta round . -1.5 -1, ceil(val + 0.5), C ceil : . 379
  • 380. 380 41 Vim Listtype() 0 1 aislocked()function()getbufvar()setbufvar()getwinvar()gettabwinvar()setwinvar()settabwinvar()garbagecollect()a :echotype(v:version) Listcol() markvirtcol() markline() markwincol() awinline()cursor()getpos()setpos()byte2line() Nline2byte()diff_filler() diff b 380
  • 381. 381 41 Vim a number col(.) 8 8 b : 1 a | 1 a 2 b | 2 b ---------------------- | 3 x ---------------------- | 4 y 3 c | 5 c diff-ed 3 - 3 4 Vim - Vim :echo diff diff(3) 2 2 Listgetline()setline()append()indent()cindent() indent according to C indentinglispindent() indent according to Lisp indentingnextnonblank()prevnonblank()search()searchpos()searchpair() find the other end of a start/skip/endsearchpairpos() start/skip/endsearchdecl() 381
  • 382. 382 41 Vim Listglob()globpath()findfile()finddir()resolve() MS-Windowsfnamemodify() apathshorten()simplify()executable()filereadable()filewritable()getfperm()getftype()isdirectory()getfsize()getcwd()haslocaldir()tempname()mkdir()delete()rename()system() SHELLhostname()readfile()writefile()a Listgetftime()localtime()strftime()reltime()reltimestr() reltime() 382
  • 383. 383 41 Vim Listargc()argidx()argv()bufexists()buflisted()bufloaded()bufname()bufnr()tabpagebuflist()tabpagenr()tabpagewinnr() winnr()winnr()bufwinnr() -1winbufnr()getbufline() Listgetcmdline()getcmdpos()setcmdpos()getcmdtype() Listgetqflist() quickfixsetqflist() quickfixgetloclist() location asetloclist() locationa vim7.0 location buftype quickfix(set ft? qf) quickfix location location quickfix grep -n pattern files : : location :grep :helpgrep :vimgrep . 383
  • 384. 384 41 Vim Listcomplete()complete_add()complete_check()pumvisible() Listfoldclosed() -1foldclosedend()foldlevel() 0foldtext() afoldtextresult()a :echo foldtext() foldtext :set foldtext=<<<.foldtext().>>> Listclearmatches() |matchadd()| |:match|getmatches() |matchadd()| |:match|hlexists()hlID() IDsynID() IDsynIDattr() IDsynIDtrans() IDdiff_hlID() diff IDmatchadd() ( )matcharg() :matchmatchdelete() |matchadd()| |:match|setmatches() |getmatches()| Listspellbadword()spellsuggest()soundfold() 384
  • 385. 385 41 Vim Listhistadd()histdel()histget()histnr() Listbrowse()browsedir()confirm()getchar()getcharmod() ainput()inputlist()inputsecret()inputdialog()inputsave() binputrestore() inputsave()a get modifiers for the last typed character getchar() ( ) : 2 shift 4 control 8 alt ( meta) 16 32 64 128 Macintosh Shift-a "A" ALT CTRL " " : 385
  • 386. 386 41 Vim 0000-0010 2 shift 0000-0100 4 control 0000-1000 8 alt ( meta) 0001-0000 16 0010-0000 32 0100-0000 64 1000-0000 128 Macintosh 0 2+4 6 shift control 00000110 getchar() getcharmod()b vim inputsave() :call inputsave()|call input("Press <cr> to continue")|call inputrestore() inputsave()/inputrestore() GUI: Listgetfontname()getwinposx() Xgetwinposy() YVim Listserverlist()remote_send()remote_expr()server2client()remote_peek()remote_read()foreground() Vimremote_foreground() Vim 386
  • 387. 387 41 Vim Listwinheight()winwidth()winrestcmd() return command to restore window sizeswinsaveview() get view of current windowwinrestview() restore saved view of current window Listmode()visualmode() Visualhasmapto()mapcheck()maparg()exists()has() Vimcscope_connection() cscopechangenr()did_filetype()eventhandler()libcall()libcallnr() intgetreg()getregtype() asetreg()taglist() tagstagfiles() tagsa Visual a getregtype(a) v normal "a3Y 3 a getregtype(’a’) V Visual <^V#>*41.7* Vim 387
  • 388. 388 41 Vim code:function {name}({var1}, {var2}, ...): {body}:endfunction : code:function Min(num1, num2) Vim "Min" "num1" "num2" code: if a:num1 < a:num2 1 "a:" Vim "smaller": code: if a:num1 < a:num2: let smaller = a:num1: else: let smaller = a:num2: endif "smaller" "g:" "a:" "s:" : "g:" "g:today" "today" "today" 1 a argument 388
  • 389. 389 41 Vim ":return" code: return smaller:endfunction code:function Min(num1, num2): if a:num1 < a:num2: let smaller = a:num1: else: let smaller = a:num2: endif: return smaller:endfunction code:function Min(num1, num2): if a:num1 < a:num2: return a:num1: endif: return a:num2:endfunction Vim Min code:echo Min(5, 8) Vim Vim ":endfunction" ":return" 0. 389
  • 390. 390 41 Vim 1 ":function" ! code:function! Min(num1, num2, num3) ":call" "range" "a:firstline" "a:lastline" code:function Count_words() range: let lnum = a:firstline: let n = 0: while lnum <= a:lastline: let n = n + len(split(getline(lnum))): let lnum = lnum + 1: endwhile: echo "found " . n . " words":endfunction ex command:10,30call Count_words() "range" code:function Number(): echo "line " . line(".") . " contains: " . getline("."):endfunction 1 Vim C 390
  • 391. 391 41 Vim ex command:10,15call Number() Number() 6 Vim 20 code:function Show(start, ...) "a:1" "a:2" "a:0" code:function Show(start, ...): echohl Title: echo "Show is " . a:start: echohl None: let index = 1: while index <= a:0: echo " Arg " . index . " is " . a:{index}: let index = index + 1: endwhile: echo "":endfunction ":echohl" ":echo" ":echohl None" ":echon" ":echo" a:000 "..." |a:000| ":function" 391
  • 392. 392 41 Vim codefunctions::functionfunction Show(start, ...)function GetVimIndent()function SetSyn(name) ":function" Display:function SetSyn1 if &syntax == 2 let &syntax = a:name3 endifendfunction |debug-scripts| verbose 12 15 Show() ex command:delfunction Show Vim function() : 392
  • 393. 393 41 Vim ex command:let result = 0 " or 1:function! Right(): return Right!:endfunc:function! Wrong(): return Wrong!:endfunc::if result == 1: let Afunc = function(Right):else: let Afunc = function(Wrong):endif:echo call(Afunc, [])Wrong! : call()*41.8* Vim ex command:let alist = [aap, mies, noot] 393
  • 394. 394 41 Vim ex command:let alist = []add() ex command:let alist = []:call add(alist, foo):call add(alist, bar):echo alist[foo, bar]+ ex command:echo alist + [foo, bar][foo, bar, foo, bar] ex command:let alist = [one]:call add(alist, [two, three]):echo alist[one, [two, three]]add()FOR ex command:let alist = [one, two, three]:for n in alist: echo n:endforonetwothree 394
  • 395. 395 41 Vim "alist" "n".for ex command:for {varname} in {listexpression}: {commands}:endfor range() ex command:for a in range(3): echo a:endfor012 range() 0 1. range() ex command:for a in range(8, 4, -2): echo a:endfor864 ex command:for line in getline(1, 20): if line =~ "Date: ": echo matchstr(line, Date: zs.*): endif:endfor 395
  • 396. 396 41 Vim 1 20 ( 20 ) - ex command:let uk2nl = {one: een, two: twee, three: drie} ex command:echo uk2nl[two]twee ex command{<key> : <value>, ...} ex command{} ex command:for key in keys(uk2nl): echo key:endforthreeonetwo : 396
  • 397. 397 41 Vim ex command:for key in sort(keys(uk2nl)): echo key:endforonethreetwo ex command:echo uk2nl[one]een ex command:echo uk2nl.oneeen ASCII ex command:let uk2nl.four = vier:echo uk2nlthree: drie, four: vier, one: een, two: twee ex command:function uk2nl.translate(line) dict: return join(map(split(a:line), get(self, v:val, "???"))):endfunction 397
  • 398. 398 41 Vim ex command:echo uk2nl.translate(three two five one)drie twee ??? een ":function" "dict" "self" return ex commandsplit(a:line)split() ex command:echo split(three two five one)[three, two, five, one] map() "v:val" ex command:let alist = map(split(a:line), get(self, v:val, "???")) ex command:let alist = split(a:line):for idx in range(len(alist)): let alist[idx] = get(self, alist[idx], "???"):endforget() ??? join() split() split(), map() join() 398
  • 399. 399 41 Vim . ex command:let transdict =:function transdict.translate(line) dict: return join(map(split(a:line), get(self.words, v:val, "???"))):endfunction self.words self.words ex command:let uk2nl = copy(transdict):let uk2nl.words = one: een, two: twee, three: drie:echo uk2nl.translate(three one)drie een ex command:let uk2de = copy(transdict):let uk2de.words = one: ein, two: zwei, three: drei:echo uk2de.translate(three one)drei ein copy() "transdict" 399
  • 400. 400 41 Vim ex command:if $LANG =~ "de": let trans = uk2de:else: let trans = uk2nl:endif:echo trans.translate(one two three)een twee drie "trans" ( ) |list-identity| |dict-identity| translate() ex command:let uk2uk = copy(transdict):function! uk2uk.translate(line): return a:line:endfunction:echo uk2uk.translate(three one wladiwostok)three one wladiwostok ! "uk2uk" ex command:if $LANG =~ "de": let trans = uk2de:elseif $LANG =~ "nl": let trans = uk2nl:else: let trans = uk2uk:endif:echo trans.translate(one two three)one two three |Lists| |Dictionaries|*41.9* 400
  • 401. 401 41 Vim code:try: read ~/templates/pascal.tmpl:catch /E484:/: echo "Sorry, the Pascal template file cannot be found.":endtry ":read" ":try" ":endtry" Vim "E484:" ( ). ":read" "E484:" code:try: read ~/templates/pascal.tmpl:catch: echo "Sorry, the Pascal template file cannot be found.":endtry "E21: Cannot make changes, modifiable is off" ":finally" 401
  • 402. 402 41 Vim code:let tmp = tempname():try: exe ".,$write " . tmp: exe "!filter " . tmp: .,$delete: exe "$read " . tmp:finally: call delete(tmp):endtry "filter" ":try" ":finally" CTRL-C ":call delete(tmp)" |exception-handling|*41.10* Vim Unix <NL> 1 2 MS-DOS, Windows OS/2 <CR><LF> <CR> mapping |:source crnl| Vim ( ) 1 NL New Line. ASCII 10 "n" 2 CR Carriage Return LF Line Feed 402
  • 403. 403 41 Vim ":set" "=" ex command:set cpoptions =aABceFst "=" "=" "": ex command:set tags=my nice file ex command:set tags=my nice file 1 Vim : ex command:set tags=my:set nice:set file " " ( " ) 2 3 1 nice file Vim tags my nice file ( set ts=2 enc) true( :set ts=2 number) 2 3 403
  • 404. 404 41 Vim List:abbrev dev development " shorthand:map <F3> o#include " insert include:execute cmd " do it:!ls *.c " list C files dev development " shorthand <F3> o#include " insertinclude. "execute" . "!" shell 1 ":map", ":abbreviate", ":execute" "!" ( ) ":map",":abbreviate" ":execute" List:abbrev dev development|" shorthand:map <F3> o#include|" insert include:execute cmd |" do it "|" "|" "|" "|" ex command:map <F4> o#include Vim list Unix Vim Display#!/usr/bin/env vim -Secho "this is a Vim script"quit 1 : shell Vim Vim shell 404
  • 405. 405 41 Vim"#" shell |:#!| |-S| ex command:map ,ab o#include:unmap ,ab unmap unmap ",ab" map Vim ":unmap ,ab " unmap ex command:unmap ,ab " comment Vim unmap ",ab " ex command:unmap ,ab|" comment ex commandmap ,p ma"aYHmbgg"aP`bzt`a ,p 405
  • 406. 406 41 Vim Listma"aYHmbgg"aP`bzt`ama a"aY aHmb bgg"aP`bzt`a • "OW " . • 1 Vim unload . 1 Vim 406
  • 407. 407 41 Vim code" This is the XXX packageif exists("XXX_loaded")delfun XXX_onedelfun XXX_twoendiffunction XXX_one(a)... body of function ...endfunfunction XXX_two(b)... body of function ...endfunlet XXX_loaded = 1*41.11* plugin *write-plugin* Vim plugin plugin |add-plugin| plugin: plugin filetype plugins plugin filetype plugin |write-filetype-plugin| plugin : plugin 407
  • 408. 408 41 Vim 1 Windows plugin 8 "typecorr.vim" plugin plugin plugin ex command14 iabbrev teh the15 iabbrev otehr other16 iabbrev wnat want17 iabbrev synchronisation18 synchronization19 let s:count = 4 plugin plugin plugin Display1 " Vim global plugin for correcting typing mistakes2 " Last Change: 2000 Oct 153 " Maintainer: Bram Moolenaar <Bram@vim.org> plugins plugins Vim |license| Display4 " License: This file is placed in the public domain. 1 8 408
  • 409. 409 41 Vim *use-cpo-save* 18 Vim |line-continuation| compatible Vim compatible cpoptions code11 let s:save_cpo = &cpo12 set cpo&vim..42 let &cpo = s:save_cpo cpoptions s:save cpo plugin |s:var| plugin plugin plugin plugin code6 if exists("loaded_typecorr")7 finish8 endif9 let loaded_typecorr = 1 autocommand 409
  • 410. 410 41 Vim plugin plugin mapping mapping mapping map <Leader> ex command22 map <unique> <Leader>a <Plug>TypecorrAdd "<Plug>TypecorrAdd" "mapleader" map codelet mapleader = "_" " a" map "mapleader" -- "a" map. <unique> Vim |:map-unique| code21 if !hasmapto(<Plug>TypecorrAdd)22 map <unique> <Leader>a <Plug>TypecorrAdd23 endif "<Plug>TypecorrAdd" map "<Leader>a". Displaymap ,c <Plug>TypecorrAdd ",c" " a" "a" map map Add() 410
  • 411. 411 41 Vim "s:" 1 code30 function s:Add(from, correct)31 let to = input("type the correction for " . a:from . ": ")32 exe ":iabbrev " . a:from . " " . to..36 endfunction s:Add() s:Add(), s:Add() Add() s:Add() <SID> map VIM ID ID plugin ex command24 noremap <unique> <script> <Plug>TypecorrAdd <SID>Add..28 noremap <SID>Add :call <SID>Add(expand("<cword>"), 1)<CR> "a" Displaya -> <Plug>TypecorrAdd -> <SID>Add -> :call <SID>Add() <SID>Add ID <SID>Add() s:Add() <SID> ID, VIM Add() plugin map <SID>Add() s:Add()( autocommands ) 1 s script 411
  • 412. 412 41 Vim Display25 noremenu <script> Plugin.Add Correction <SID>Add "Plugin" CVS "Plugin.CVS.checkin", "Plugin.CVS.checkout" "Plugin.CVS" 28 ":noremap" map ":call" 24 ":noremap" "<SID>Add" "<script>" mapping |:map-script| 26 ":noremenu"<SID> <Plug> *using-<Plug>* <SID> <Plug> <Plug> <Plug> <Plug> "Typecorr" "Add" "<Plug>TypecorrAdd" <SID> ID Vim <SID> "<SNR>123 " "123" "<SID>Add()" "<SNR>11 Add()", "<SNR>22 Add()" ":function" <SID> code38 if !exists(":Correct")39 command -nargs=1 Correct :call s:Add(<q-args>, 0)40 endif 412
  • 413. 413 41 Vim ":command!" |:command| "s:" Vim code19 let s:count = 4..30 function s:Add(from, correct)..34 let s:count = s:count + 135 echo s:count . " corrections now"36 endfunction s:count 4 s:Add() 1 413
  • 414. 414 41 Vim code1 " Vim global plugin for correcting typing mistakes2 " Last Change: 2000 Oct 153 " Maintainer: Bram Moolenaar <Bram@vim.org>45 if exists("loaded_typecorr")6 finish7 endif8 let loaded_typecorr = 1910 let s:save_cpo = &cpo11 set cpo&vim1213 iabbrev teh the14 iabbrev otehr other15 iabbrev wnat want16 iabbrev synchronisation17 synchronization18 let s:count = 41920 if !hasmapto(<Plug>TypecorrAdd)21 map <unique> <Leader>a <Plug>TypecorrAdd22 endif23 noremap <unique> <script> <Plug>TypecorrAdd <SID>Add2425 noremenu <script> Plugin.Add Correction <SID>Add2627 noremap <SID>Add :call <SID>Add(expand("<cword>"), 1)<CR>2829 function s:Add(from, correct)30 let to = input("type the correction for " . a:from . ": ")31 exe ":iabbrev " . a:from . " " . to32 if a:correct | exe "normal viws<C-R>" be" | endif33 let s:count = s:count + 134 echo s:count . " corrections now"35 endfunction3637 if !exists(":Correct")38 command -nargs=1 Correct :call s:Add(<q-args>, 0)39 endif40 41441 let &cpo = s:save_cpo
  • 415. 415 41 Vim 33 word |:normal| ":noremap" fileformat "unix" Vim fileformat "dos" Unix |:source crn| shell command:set fileformat=unix *write-local-help* plugin plugin |add-local-help| plugin "typecorr.txt": Display1 *typecorr.txt* Plugin for correcting typing mistakes23 If you make typing mistakes, this plugin will have them corrected4 automatically.56 There are currently only a few corrections. Add your own if you like.78 Mappings:9 <Leader>a or <Plug>TypecorrAdd10 Add a correction for the word under the cursor.1112 Commands:13 :Correct word14 Add a correction for word1516 *typecorr-settings*17 This plugin doesnt have any settings. help.txt "LOCAL ADDITIONS:" |local-additions| "*" 415
  • 416. 416 41 Vim ** plugin "typecorr-settings" || *plugin-special* plugin s:name <SID> ID hasmapto() <Leader> "mapleader" plugin :map <unique> :noremap <script> exists(":Cmd")*41.12* plugin *write-filetype-plugin**ftplugin* plugin plugin |add-filetype-plugin| plugin. |41.10| plugin plugin plugin plugin plugin 416
  • 417. 417 41 Vim code" Only do this when not done yet for this bufferif exists("b:did_ftplugin")finishendiflet b:did_ftplugin = 1 plugin ( ":edit" ) plugin plugin: ex commandlet b:did_ftplugin = 1 / plugin runtimepath $VIMRUNTIME plugin ex commandsetlocal textwidth=70 "after" "vim.vim" |after-directory| Unix "~/.vim/after/ftplugin/vim.vim" plugin "b:did ftplugin" plugin ex command:setlocal ( ) |:setlocal| plugin 417
  • 418. 418 41 Vim "+=" "-=" ex command:setlocal formatoptions& formatoptions+=ro ex command:map <buffer> plugin codeif !hasmapto(<Plug>JavaImport)map <buffer> <unique> <LocalLeader>i <Plug>JavaImportendifnoremap <buffer> <unique> <Plug>JavaImport oimport ""<Left><Esc> |hasmapto()| <Plug>JavaImport |<LocalLeader>| "<unique>" |:noremap| ":noremap<script>" <SID> plugin plugin code" Add mappings, unless the user didnt want this.if !exists("no_plugin_maps") && !exists("no_mail_maps")" Quote text by inserting "> "if !hasmapto(<Plug>MailQuote)vmap <buffer> <LocalLeader>q <Plug>MailQuotenmap <buffer> <LocalLeader>q <Plug>MailQuoteendifvnoremap <buffer> <Plug>MailQuote :s/^/> /<CR>nnoremap <buffer> <Plug>MailQuote :.,$s/^/> /<CR>endif 418
  • 419. 419 41 Vim no plugin maps pluginsno mail maps plugin 1 |:command| "-buffer" : ex command:command -buffer Make make %:r.s Vim plugin |s:var| plugin code:if !exists("*s:Func"): function s:Func(arg): ...: endfunction:endif *undo ftplugin* ":setfiletype xyz" "b:undo ftplugin" ex commandlet b:undo_ftplugin = "setlocal fo< com< tw< commentstring<" . "| unlet b:match_ignorecase b:match_words b:match_skip" ":setlocal" "<" 1 one buffer 419
  • 420. 420 41 Vim cpoptions "C" |use-cpo-save| plugin |ftplugin-name| 3 List.../ftplugin/stuff.vim.../ftplugin/stuff_foo.vim.../ftplugin/stuff/bar.vim "stuff" "foo" "bar" .. *ftplugin-special* plugin <LocalLeader> "maplocalleader" plugin :map <buffer> :noremap <script> <SID> :setlocal :command -buffer exists("*s:Func") |plugin-special| plugin*41.13* plugin *write-compiler-plugin* plugin |:compiler| errorformat makeprg plugin: ex command:next $VIMRUNTIME/compiler/*.vim 420
  • 421. 421 41 Vim |:next| plugin code:if exists("current_compiler"): finish:endif:let current_compiler = "mine" plugin runtime ( Unix ~/.vim/compiler) "current compiler" plugin ":set" ":compiler!" ":setlocal" ":compiler". Vim ":CompilerSet" Vim plugin ex commandif exists(":CompilerSet") != 2command -nargs=* CompilerSet setlocal <args>endifCompilerSet errorformat& " use the default errorformatCompilerSet makeprg=nmake Vim plugin "current compiler" plugin plugin plugin "current compiler" plugin runtimepath Unix ~/.vim/runtime/after/compiler.41.14 plugin *write-plugin-quickload* 421
  • 422. 422 41 Vim Vim 7 |autoload| |41.15| ex command" Vim global plugin for demonstrating quick loading" Last Change: 2005 Feb 25" Maintainer: Bram Moolenaar <Bram@vim.org>" License: This file is placed in the public domain.if !exists("s:did_load")command -nargs=* BNRead call BufNetRead(<f-args>)map <F19> :call BufNetWrite(something)<CR>let s:did_load = 1exe au FuncUndefined BufNet* source . expand(<sfile>)finishendiffunction BufNetRead(...)echo BufNetRead( . string(a:000) . )" read functionality hereendfunctionfunction BufNetWrite(...)echo BufNetWrite( . string(a:000) . )" write functionality hereendfunction "s:did load" "if" "endif" |:finish| 422
  • 423. 423 41 Vim "s:did did" "endif" ( )BufNetRead() BufNetWrite() Vim 1 "BNRead" <F19> |FuncUndefined| ":finish" 2 BNRead <F19> BufNetRead() BufNetWrite() 3. Vim |FuncUndefined| "BufNet*" "source fname" "fname" "<sfile>" ( |expand()|). 4 "s:did load" |FuncUndefined|41.15 *write-library-script* |exists()| ex commandif !exists(*MyLibFunction)runtime library/mylibscript.vimendifcall MyLibFunction(arg) MyLibFunction() runtimepath "library/mylibscript.vim" 423
  • 424. 424 41 Vim Vim autoload ex commandcall mylib#myfunction(arg) Vim runtimepath "autoload/mylib.vim" "mylib#myfunction" mylib.vim # Vim ex commandcall netlib#ftp#read(somefile) Unix Display~/.vim/autoload/netlib/ftp.vim ex commandfunction netlib#ftp#read(fname)" Read the file fname through ftpendfunction # ex commandlet weekdays = dutch#weekdays "autoload/dutch.vim" ex commandlet dutch#weekdays = [zondag, maandag, dinsdag, woensdag, donderdag, vrijdag, zaterdag] 424
  • 425. 425 41 Vim |autoload|41.16 Vim *distribute-script*Vim Vim http://www.vim.org Vim tar gzip / "zip" Vim Vimball |vimball| |glvs-plugins| |usr 42.txt| |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 425
  • 426. 426 42*usr 42.txt* Vim 7.0 . 2008 05 05 VIM --- Bram Moolenaar Vim GUI|42.1||42.2||42.3| Various|42.4| |usr 43.txt| filetypes |usr 41.txt| Vim |usr toc.txt|*42.1* vim "$VIMRUNTIME/menu.vim" ":menu" ex command:menu {menu-item} {keys} {menu-item} {menu-item} "File.Save", "File" "Save" ex command:menu File.Save :update<CR> ":update" 426
  • 427. 427 42 "Edit.Settings.Shiftwidth" "Edit" "Settings" "Shiftwidth" ":menu" ":map" {keys} {keys} & ALT-F "File" S "Save" ( winaltkyes ) {menu-item} "&File.&Save" Vim File.Save ex command:menu 10.340 &File.&Save<Tab>:w :confirm w<CR> 10.340 Vim (10) Display 10 20 40 50 60 70 9999+------------------------------------------------------+| File Edit Tools Syntax Buffers Window Help |+------------------------------------------------------+ Help (340) File 427
  • 428. 428 42 Display +-----------------+10.310 |Open... |10.320 |Split-Open... |10.325 |New |10.330 |Close |10.335 |---------------- |10.340 |Save |10.350 |Save As... |10.400 |---------------- |10.410 |Split Diff with |10.420 |Split Patched By |10.500 |---------------- |10.510 |Print |10.600 |---------------- |10.610 |Save-Exit |10.620 |Exit | +-----------------+ .( ) ". " {menu-item} "&File.&Save<Tab>:w" : {menu-item} ( <space> <tab>) ex command:menu 10.305 &File.&Do It... :exit<CR> "Do It..." ":exit<CR>" <Tab> <Tab> File.Save "&File.Save<Tab>:w" "File.Save" ":w" 428
  • 429. 429 42 "-" "-sep-" ex command:amenu 20.510 Edit.-sep3- :*42.2* ":map" List:menu Normal, Visual and Operator-pending mode:nmenu Normal mode:vmenu Visual mode:omenu Operator-pending mode:menu! Insert and Command-line mode:imenu Insert mode:cmenu Command-line mode:amenu All modes ":map" ":noremenu", ":nnoremenu", ":anoremenu" :AMENU ":amenu" {keys} Visual Vim Normal ":amenu" CTRL-C CTRL-O ex command:amenu 90.100 Mine.Find Word * 429
  • 430. 430 42 ListNormal mode: *Visual mode: CTRL-C *Operator-pending mode: CTRL-C *Insert mode: CTRL-O *Command-line mode: CTRL-C * CTRL-C Visual CTRL-C CTRL-O Normal CTRL-O Normal code:amenu Mine.Next File :call <SID>NextFile()<CR>:function <SID>NextFile(): next: 1/^Code:endfunction ":next" "Code" <SID> ID Vim |<SID>|. {kyes} ":" ‘ ENTER ’ <silent> NextFile() ex command:call <SNR>34_NextFile() <silent> ex command:amenu <silent> Mine.Next File :call <SID>NextFile()<CR> 430
  • 431. 431 42 "<silent>" {keys} ( ). {menu-item} ex command:amenu ex command:amenu Edit "Edit" ex command:imenu Edit.Undo "&" <Tab> "menu" "unmenu". ":menu" ":unmenu","nmenu" "nunmenu" "Tools.Make" ex command:iunmenu Tools.Make ex command:aunmenu Syntax 431
  • 432. 432 42 Syntax*42.3* guioptions "M" List:set guioptions-=mmMg ( )t (tearoff tear-off " ") |:menutrans| ":browse" ":confirm" ex command:amenu File.Open :browse confirm edit<CR> ":browse" ":confirm" confirm() inputdialog()*42.4* 432
  • 433. 433 42 guioptions "T" "ToolBar.New" {menu-item} "New" Vim 28 |builtin-tools| ex command:tmenu ToolBar.Compile Compile the current file:amenu ToolBar.Compile :!cc % -o %:r<CR> MS-Windows bitmap "Compile.bmp". Unix XPM "Compile.xpm".1 18 x 18 MS-Windows bitmap runtimepath "bitmaps" Unix "~/.vim/bitmaps/Compile.xpm" "Open file" ex command:tmenu ToolBar.Make Run make in the current directory : "Toolbar" "toolbar" "ToolBar"! |:tunmenu| toolbar 1 : MS-Windows Unix 433
  • 434. 434 42 MS-Windows Unix 1 mousemodel popup popup setpos "popup setpos" |usr 43.txt| |manual-copyright| vim:tw=78:ts=4:ft=help:norl: 1 Xwindows 434
  • 435. 435 43*usr 43.txt* Vim 7.0 . 2006 04 24 VIM --- Bram Moolenaar C shell|43.1||43.2| |usr 44.txt| |usr 42.txt| |usr toc.txt|*43.1* *filetype-plugin* |add-filetype-plugin| C softtabstop 4 *your-runtime-dir* 1 Unix "~/.vim" 1 "ftplugin" shell commandmkdir ~/.vimmkdir ~/.vim/ftplugin 1 : ft+plugin ftp + lugin 435
  • 436. 436 43 Unix runtimepath Vim "ftplugin" ex commandset runtimepath ( ) |vimrc| runtimepath 2 "~/.vim/ftplugin/c.vim" ex commandsetlocal softtabstop=4noremap <buffer> <LocalLeader>c o/**************<CR><CR>/<Esc> C softtabstop 1 4 ":setlocal" softtabstop ":set" "c" ":map<buffer>" ":map!", ":vmap" |<LocalLeader>| "maplocalleader" List$VIMRUNTIME/ftplugin/ filetype |write-plugin|*43.2* filetype 2 Vim Vim |your-runtime-dir| 1 :set softtabstop 2 436
  • 437. 437 43 "filetype.vim" filetype autocommand. (Autocommands |40.3| .) ex commandaugroup filetypedetectau BufNewFile,BufRead *.xyz setf xyzaugroup END Vim ".xyz" "xyz" ":augroup" autocommand "filetypedetect" ":filetype off" autocommand. "setf" filetype filetype filetype |autocmd-patterns| "/usr/share/scripts/" "ruby" filetype: ex commandaugroup filetypedetectau BufNewFile,BufRead *.xyz setf xyzau BufNewFile,BufRead /usr/share/scripts/* setf rubyaugroup END /usr/share/scripts/README.txt ruby "*" filetype.vim runtimepath Unix "~/.vim/after/filetype.vim" ~/.vim/filetype.vim ex commandaugroup filetypedetectau BufNewFile,BufRead *.txt setf textaugroup END "filetype.vim" runtimepath ~/.vim/after/filetype.vim: 437
  • 438. 438 43 ex commandaugroup filetypedetectau BufNewFile,BufRead /usr/share/scripts/* setf rubyaugroup END Vim runtimepath "filetype.vim" ~/.vim/filetype.vim *.txt autocommand .txt filetype text Vim runtimepath $VIMRUNTIME ~/.vim/after/filetype.vim /usr/share/scripts/ /usr/share/scripts/README.txt, autocommand "*.txt" "setf text" "text". ruby "setf ruby" filetype "text" "setf ruby" /usr/share/scripts/foobar, Vim autocommand ruby filetype ruby. Display#!/bin/xyz ( filetype.vim ) "scripts.vim" codeif did_filetype() finishendifif getline(1) =~ ^#!.*[/]xyz> setf xyzendif did filetype() filetype 438
  • 439. 439 43 scripts.vim filetype.vim autocommand 1. runtimepath $VIMRUNTIME filetype.vim 2. $VIMRUNTIME/filetype.vim 3. runtimepath scripts.vim 4. $VIMRUNTIME/filetype.vim 5. runtimepath $VIMRUNTIME filetype.vim autocommand |usr 44.txt| |manual-copyright| vim:tw=78:ts=4:ft=help:norl: 439
  • 440. 440 44*usr 44.txt* Vim 7.0 . 2006 04 24 VIM --- Bram Moolenaar Vim |syn-define||44.1||44.2||44.3||44.4||44.5||44.6||44.7||44.8||44.9||44.10||44.11||44.12| |usr 45.txt| |usr 43.txt| |usr toc.txt|*44.1* $VIMRUNTIME/syntax 440
  • 441. 441 44 ex command:syntax clear ex command:syntax ex command:syntax list {group-name} @ ( |44.8| ) Pascal C ex command:syntax case match:syntax case ignore "match" Vim "int" "Int" "INT" 441
  • 442. 442 44 "ignore", "Procedure", "PROCEDURE" "procedure" ":syntax case" ":syntaxcase" ":syntax case"*44.2* ex command:syntax keyword {group} {keyword} ... {group} ":highlight" {group} {keyword} ex command:syntax keyword xType int long char:syntax keyword xStatement if then else endif "xType" "xStatement" filetype x ( eXample ) "csh" "cshType" filetype "int", "long" "char" "then", "else" "endif" x Vim ex command:highlight link xType Type:highlight link xStatement Statement Vim "xType" "Type" "xStatement" "Statement" |group-name| 442
  • 443. 443 44 iskeyword Vim x "-" ex command:setlocal iskeyword+=-:syntax keyword xStatement when-not ":setlocal" "iskeyword" "w" "*" match ( ). x "next" "n", "ne" "nex" ex command:syntax keyword xStatement n[ext] "nextone"*44.3* match ex command:syntax match xIdentifier /<l+>/ : "if", "then" xIdentifier. // ( :substitute ) / + " x # 443
  • 444. 444 44 ex command:syntax match xComment /#.*/ |pattern|*44.4* x ex command:syntax region xString start=/"/ end=/"/ "start" "end" ex command"A string with a double quote (") in it" Vim " skip ex command:syntax region xString start=/"/ skip=/"/ end=/"/ region match match "start" "end" "end" region*44.5* 444
  • 445. 445 44 Display%Get input TODO: Skip white space TODO Vim ex command:syntax keyword xTodo TODO contained:syntax match xComment /%.*/ contains=xTodo "contained" Vim "contains=xTodo" xTodo "xComment" TODO xTodo x {} ex command:syntax region xBlock start=/{/ end=/}/ contains=xBlock x codewhile i < b { if a { b = c; }} xBlock { { xBlock "b = c" xBlock } xBlock xBlock } xBlock xBlock } xBlock 445
  • 446. 446 44 ex command:syntax region xComment start=/%/ end=/$/ contained:syntax region xPreProc start=/#/ end=/$/ contains=xComment % # "contains=xComment" code#define X = Y % Comment textint foo = 1; xPreProc "end=/$/" % "keepend" Vim ex command:syntax region xComment start=/%/ end=/$/ contained:syntax region xPreProc start=/#/ end=/$/ contains=xComment keepend contains ex command:syntax region xList start=/[/ end=/]/ contains=ALL xList xList( ). 446
  • 447. 447 44 ex command:syntax region xList start=/[/ end=/]/ contains=ALLBUT,xString "contains=TOP" "contained" "contains=CONTAINED" "contained" |:syn-contains|*44.6* x codeif (condition) then "(condition)" "then" ex command:syntax match xIf /if/ nextgroup=xIfCondition skipwhite:syntax match xIfCondition /([^)]*)/ contained nextgroup=xThen skipwhite:syntax match xThen /then/ contained "nextgroup" Vim codeif not (condition) then "if" xIf "not" nextgroup xIfCondition "if" "skipwhite" Vim ( ) "skipnl" "skipempty" "skipnl" 447
  • 448. 448 44*44.7* () xInside ex command:syntax region xInside start=/(/ end=/)/ "matchgroup" Vim .( xParen ): ex command:syntax region xInside matchgroup=xParen start=/(/ end=/)/ "matchgroup" start end xParen ex command:syntax region xInside matchgroup=xParen start=/(/ matchgroup=xParenEnd end=/)/ "matchgroup" "transparent" C "while" () "for" () () () () ex command:syntax region cWhile matchgroup=cWhile start=/whiles*(/ end=/)/ contains=cCondNest:syntax region cFor matchgroup=cFor start=/fors*(/ end=/)/ contains=cCondNest:syntax region cCondNest start=/(/ end=/)/ contained transparent 448
  • 449. 449 44 cWhile cFor cCondNest "transparent" "matchgroup" matchgroup cCondNest "while" "for" ( cCondNest "( ")" cCondNest "(" "if" "()" "if" "(", ")" ex command:syntax region xCond start=/ifs*(/ms=e+1 end=/)/me=s-1 "ms=e+1". "ms" "Match Start" "e+1" Vim 1 "me=s-1". "me" "Match End" "s-1" 2 "foo == bar" xCond |:syn-pattern-offset| "online" Vim ex command:syntax region xIfThen start=/if/ end=/then/ oneline "if" "then" "if" "then" 1 if( foo == bar ) ::syntax region xCond start=/ifs*(s*/ms=e+1 end=/s*)/me=s-1 2 "1234" 2 1 / 1 2 / . 449
  • 450. 450 44 : "oneline" "oneline" Vim # ex command:syntax region xPreProc start=/^#/ end=/$/ contains=xLineContinue:syntax match xLineContinue "$" contained xPreProc ( xLineContinue) code#define SPAM spam spam spam bacon and spam "excludenl" xPreProc "end", xPreProc xLineContinue "excludenl": ex command:syntax region xPreProc start=/^#/ end=/$/ contains=xLineContinue,xPreProcEnd:syntax match xPreProcEnd excludenl /end$/ contained:syntax match xLineContinue "$" contained "excludenl" "xLineContinue" "excludenl" xPreProc*44.8* 450
  • 451. 451 44 Vim Vim if while ex command:syntax match xFor /^for.*/ contains=xNumber,xIdent:syntax match xIf /^if.*/ contains=xNumber,xIdent:syntax match xWhile /^while.*/ contains=xNumber,xIdent "contains=" 3 ex command:syntax cluster xState contains=xNumber,xIdent syntax @ ex command:syntax match xFor /^for.*/ contains=@xState:syntax match xIf /^if.*/ contains=@xState:syntax match xWhile /^while.*/ contains=@xState "add" ex command:syntax cluster xState add=xString ex command:syntax cluster xState remove=xNumber*44.9* C++ C Vim 451
  • 452. 452 44 ex command:runtime! syntax/c.vim ":runtime!" runtimepath "syntax/c.vim" C C c.vim C++ C C++ C ex command:syntax keyword cppStatement new delete this friend using Perl Perl POD POD "=head" 1 "=cut" POD Perl ":syntax include" ex command:syntax include Pod <sfile>:p:h/pod.vim @:syntax region perlPOD start=/^=head/ end=/^=cut/ contains=@Pod Perl "=head", perlPOD Pod @ pod.vim "=cut" Perl ":syntax include" ":syntaxclear" "contain=ALL" include "<sfile>:p:h/" (<sfile>) (:p) (:h) pod.vim 1 POD: Plain Old Documentation 452
  • 453. 453 44*44.10* Vim ":syntax sync" Vim Vim C ex command:syntax sync ccomment "minlines" Vim "maxlines" Vim 10 ex command:syntax sync ccomment minlines=10 maxlines=500 500 ( "maxlines" Vim ) Vim "display" Comment ex command:syntax sync ccomment xAltComment C Vim Vim 150 ex command:syntax sync minlines=150 453
  • 454. 454 44 "minlines" Vim ex command:syntax sync match {sync-group-name} grouphere {group-name} {pattern} Vim {pattern} {sync-group-name} shell if "if" "fi" codeif [ -f file.txt ] ; then echo "File exists"fi "grouphere" ex command:syntax sync match shIfSync grouphere shIf "<if>" "groupthere" Vim if/fi ex command:syntax sync match shIfSync groupthere NONE "<fi>" NONE Vim if "grouphere" "groupthere" {} ex command:syntax sync match xSpecial /{.*}/ |syn-sync|*44.11* 454
  • 455. 455 44 runtimepath "syntax" Unix "~/.vim/syntax" ".vim" x List~/.vim/syntax/x.vim Vim |43.2| Vim email Vim <maintainer@vim.org> Vim Vim C ex command:syntax keyword cType off_t uint "c.vim" runtimepath Unix List~/.vim/after/syntax/c.vim*44.12* Vim 455
  • 456. 456 44 Display" Vim syntax file" Language: C" Maintainer: Bram Moolenaar <Bram@vim.org>" Last Change: 2001 Jun 18" Remark: Included by the C++ syntax. "name.vim",filetype, b:current syntax ( nameType,nameStatement, nameString ). "b:current syntax" runtimepath ex commandif exists("b:current_syntax") finishendif Vim5.8 ex commandif version < 600 syntax clearelseif exists("b:current_syntax") finishendif "b:current syntax" "b:current syntax" Vim5.x v:version yacc.vim. 456
  • 457. 457 44 tabstop,expandtab plugin iskeyword 8 "hi def link" ex commandhi def link nameString Stringhi def link nameNumber Numberhi def link nameCommand Statement... etc ... "display" CTRL-L |usr 45.txt| |manual-copyright| vim:tw=78:ts=4:ft=help:norl: 457
  • 458. 458 45*usr 45.txt* Vim 7.0 . 2008 04 30 VIM --- Bram Moolenaar ---<< >> Vim|45.1||45.2||45.3||45.4||45.5| |usr 90.txt| Vim |usr 44.txt| |usr toc.txt|*45.1* Vim ( ) ex command:language "C" 458
  • 459. 459 45 : Vim Vim ":version" "+gettext" "+multi lang". "-gettext" "-multi lang" Vim Vim Unix shell commandenv LANG=de_DE.ISO_8859-1 vim GUI Vim Vim ex command:language fr_FR.ISO_8859-1 Vim "/usr/share/locale" "/usr/lib/locale" "setlocale" "-" " " |:language|DIY-- Vim GNU gettext src/po/README.txt 459
  • 460. 460 45 vim web ( http://vim.sf.net ) email Vim <<maintainer@vim.org>>*45.2* "File" "Datei" ex command:set langmenu=none ex command:set langmenu=nl_NL.ISO_8859-1 "-" " " langmenu langmenu langmenu vimrc Vim ex command:source $VIMRUNTIME/delmenu.vim:set langmenu=de_DE.ISO_8859-1:source $VIMRUNTIME/menu.vim 460
  • 461. 461 45 List $VIMRUNTIME/lang menu {language}.vim ":language" {language} runtimepath Unix ex command:!cp $VIMRUNTIME/lang/menu_ko_kr.euckr.vim ~/.vim/lang/menu_nl_be.iso_8859-1.vim "$VIMRUNTIME/lang/README.txt" *45.3* Vim "latin1" 256 Unicode Vim 3 : Vim ":version" "+multi byte" "-multi byte" Vim 461
  • 462. 462 45 GUI UNICODE Unicode Vim Unicode Unicode Vim Unicode GUI Vim Unicode ex command:set encoding=utf-8:set guifont=-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1 encoding Vim ( ) Vim encoding Vim X-Windows xterm Unicode URLhttp://www.cl.cam.ac.uk/~mgk25/download/ucs-fonts.tar.gz MS-Windows Unicode "CourierNew" "Edit/Select Font..." ex command:set guifont=courier_new:h12 fontpack URLhttp://www.microsoft.com/typography/fonts/default.aspx 462
  • 463. 463 45 Vim Unicode Unicode Unicode termencoding Vim ex command:let &termencoding = &encoding:set encoding=utf-8 encoding termencoding encoding utf-8 Unicode Unicode Unicode Unicode XFree86 xterm xterm Unicode |UTF8-xterm| "-u8" xterm shell commandxterm -u8 -fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1 Vim encoding "utf-8" Unicode Unicode Unicode Vim ex command:let &termencoding = &encoding:set encoding=utf-8 GUI Vim termencoding encoding Vim latin1 Unicode |+iconv| 463
  • 464. 464 45 Unicode Vim ( ) normal mode commandga Vim Unicode : encoding Vim ASCII viminfo ( ) vimrc encoding*45.4* Vim Unicode 16-bit Unicode Vim utf-8 16-bit (Unicode) (utf-8 utf-16) Vim fileencodings Unicode "ucs-bom,utf-8,latin1" Vim Listucs-bom 16-bit 32-bit utf-8utf-8 utf-8 utf-8latin1 8-bit 16 Unicode Vim utf-8.fileencoding ( s) 464
  • 465. 465 45 "ucs-2le" Unicode little-endian MS-Windows ( ). Vim fileencoding encoding fileencoding encoding fileencodings Vim Vim "latin1" utf-8 ex command:set fileencodings=ucs-bom,utf-8,sjis |encoding-values| Vim Vim ex command:edit ++enc=koi8-r russian.txt "++enc" Vim Vim encoding fileencoding Vim ex command:write ++enc=utf-8 russian.txt : Unicode Unicode 465
  • 466. 466 45*45.5* Unicode 1 digraphs |24.9| Vim |mbyte-XIM|( X-Windows) |mbyte-IME|( MS-Windows). 1 latin Vim ex command:set keymap=hebrew Vim encoding Insert Normal Vim normal mode commandCTRL-^ Insert Command-line Normal ( ). showmode GUI Vim 1 466
  • 467. 467 45 iminsert imsearch ex command:lmap GUI Edit/Keymap ex command:echo globpath(&rtp, "keymap/*.vim") DIY Vim "keymap" Unix "~/.vim/keymap" List keymap/{name}.vimor keymap/{name}_{encoding}.vim {name} ( ) Listkeymap/hebrew.vimkeymap/hebrew_utf-8.vim Vim |mbyte-keymap| CTRL-V 467
  • 468. 468 45 Listencoding type range8-bit CTRL-V 123 decimal 0-2558-bit CTRL-V x a1 hexadecimal 00-ff16-bit CTRL-V u 013b hexadecimal 0000-ffff31-bit CTRL-V U 001303a4 hexadecimal 00000000-7fffffff |i CTRL-V digit| |usr 90.txt| Vim |manual-copyright| vim:tw=78:ts=8:ft=help:norl: 468
  • 469. 469 90 Vim*usr 90.txt* Vim 7.0 . 2006 04 24 VIM --- Bram Moolenaar Vim *install* Vim|90.1| Unix|90.2| MS-Windows|90.3||90.4||90.5| Vim |usr 45.txt| |usr toc.txt|*90.1* Unix Vim Vim "/usr/local" Vim home "bin" "shared/vim" UNIX URL http://www.vim.org/binaries.html 469
  • 470. 470 90 Vim UNIX Vim Vim Linux, "vi" Vim Linux Vim Vim List- C ( GCC)- GZIP ( www.gnu.org )- Vim Vim ftp://ftp.vim.org/pub/vim/MIRRORS ftp.vim.org "unix" 4 6.1 Listvim-6.1.tar.bz2 bzip2 4 gzip Vim 6.1 4 Listvim-6.1-src1.tar.gzvim-6.1-src2.tar.gzvim-6.1-rt1.tar.gzvim-6.1-rt2.tar.gz 470
  • 471. 471 90 Vim shell commandmkdir ~/vimcd ~/vim shell commandbzip2 -d -c path/vim-6.1.tar.bz2 | tar xf - shell commandgzip -d path/vim-6.1-src1.tar.gz | tar xf -gzip -d path/vim-6.1-src2.tar.gz | tar xf -gzip -d path/vim-6.1-rt1.tar.gz | tar xf -gzip -d path/vim-6.1-rt2.tar.gz | tar xf - shell commandcd vim61/srcmake make Makefile shell commandmake test 471
  • 472. 472 90 Vim Vim Displaytest results:ALL DONE Vim Vim |maillist-archive| |maillist| *install-home* home Makefile Display#prefix = $(HOME) #. Vim root Vim shell commandmake install ex command:help:syntax enable Vim ex command:echo $VIMRUNTIME 472
  • 473. 473 90 Vim shell commandvim -V Vim |not-compatible| Vim Vim Makefile "configure" Makefile List--prefix={directory} Vim--with-features=tiny--with-features=small--with-features=big--with-features=huge |+feature-list|--enable-perlinterp Perl ruby, python tcl--disable-gui GUI--without-x X-windows Vim X shell command./configure --help 473
  • 474. 474 90 Vim |feature-list| &