home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / editor-faq / vim / text0000.txt < prev    next >
Encoding:
Text File  |  1998-02-10  |  38.1 KB  |  939 lines

  1. Archive-name: editor-faq/vim
  2. Posting-Frequency: monthly (second Monday)
  3. Last-modified: Mon Feb  9 21:27:50 EST 1998
  4. URL: http://www.grafnetix.com/~laurent/vim/faq.html
  5.  
  6.                              The Vim Editor FAQ
  7.  
  8. Created: Tue Mar 12 00:00:00 EST 1996
  9. Last Updated: Date: 1998/02/08 18:03:21
  10. Version: Revision: 1.25
  11. Author: Laurent DUPERVAL <laurent@grafnetix.com>
  12. This Page: <URL:http://www.grafnetix.com/~laurent/vim/faq.html>
  13. Vim Pages: <URL:http://www.vim.org/>
  14.  
  15. This article contains answers to Frequently Asked Questions about the Vim
  16. editor. Questions marked by  [CHANGED] are questions that have been modified
  17. since the last release of the FAQ. Questions marked by  [NEW] are new
  18. questions. The following topics are addressed:
  19.  
  20. Contents
  21.  
  22.    * Contents
  23.    * 1 ABOUT THIS FAQ
  24.         o 1.1 What versions of Vim does this FAQ cover?
  25.         o 1.2 Who maintains this FAQ?
  26.         o 1.3 Why him?
  27.         o 1.4 Can I add to it?
  28.         o 1.5 What are the restrictions on this FAQ?
  29.         o 1.6  [CHANGED] Acknowledgements
  30.    * 2 GENERAL INFORMATION
  31.         o 2.1 What is Vim?
  32.         o 2.2 Who wrote Vim?
  33.         o 2.3 Is Vim compatible with Vi?
  34.         o 2.4 What are some of the improvements of Vim over Vi?
  35.         o 2.5 What are the improvements of Vim 4 over Vim 3.x?
  36.         o 2.6 What are the improvements of Vim 5.x over Vim 4.x?
  37.         o 2.7 Is Vim free?
  38.    * 3 RESOURCES
  39.         o 3.1  [CHANGED] Where can I learn more about Vim?
  40.         o 3.2 Is there a mailing list available?
  41.         o 3.3 Is there an archive available for the Vim mailing list?
  42.         o 3.4  [CHANGED] Where can I report bugs?
  43.         o 3.5 Where can the FAQ be found?
  44.         o 3.6 What if I don't find an answer in this FAQ?
  45.    * 4 AVAILABILITY
  46.         o 4.1  [CHANGED] What is the latest version of Vim?
  47.         o 4.2 Where can I find the latest version of Vim?
  48.         o 4.3  [CHANGED] What platform does it run on?
  49.         o 4.4  [CHANGED] What do I need to compile and install Vim?
  50.    * 5 TIPS AND TECHNIQUES
  51.         o 5.1 How do I use the help files?
  52.         o 5.2 Why is a backup file written even if I set nobackup?
  53.         o 5.3 How can I keep Vim from beeping all the time?
  54.         o 5.4 How do I map the Tab key?
  55.         o 5.5 How do I map the Esc key?
  56.         o 5.6 How do I tell Vim where the helpfile is?
  57.         o 5.7 How do I get back to the exact position within a line I have
  58.           marked with 'a'?
  59.         o 5.8 How do I read in the output of a command?
  60.         o 5.9 Why can't I abbreviate ``'xy''?
  61.         o 5.10 How do I jump to the beginning/end of the highlighted text?
  62.         o 5.11 Why does completion of ``:set n'' not show negated settings,
  63.           e.g., ``noautoindent''? Completion of ``:set no'' seems to work.
  64.         o 5.12 Is there a command to remove any or all digraphs?
  65.         o 5.13 How do I use a spell checker with Vim?
  66.         o 5.14 Can I copy the character above the cursor to the current
  67.           cursor position?
  68.         o 5.15 How do I remove empty lines?
  69.         o 5.16 How do I reduce a range of empty lines into one line only?
  70.         o 5.17 How can I paste large amounts of text between two running
  71.           sessions of Vim?
  72.         o 5.18 Can I use compressed versions of the help files?
  73.         o 5.19 How come I can't set option ``xxxx''?
  74.         o 5.20 How do I format a block of C code?
  75.         o 5.21 How do I put a command onto the command history without
  76.           executing it?
  77.         o 5.22 Why do I hear a beep (why does my window flash) about 1
  78.           second after I hit the Escape key?
  79.         o 5.23 How do I make the 'c' and 's' commands display a '$' instead
  80.           of deleting the characters I'm changing?
  81.         o 5.24 How do I add a line before each line with ``pattern'' in it?
  82.         o 5.25 How can I delete the newline which is followed by a given
  83.           character, such as ``|''?
  84.         o 5.26 How do I use the join command within a range of lines that
  85.           ends with ``*'' and begins with the previous ``|''?
  86.         o 5.27 How do I map/unmap an abbreviation or a map!ed key sequence?
  87.         o 5.28 When I use my arrow keys, Vim changes modes, inserts weird
  88.           characters in my document but doesn't move the cursor properly.
  89.           What's going on?
  90.         o 5.29 How do I ``auto-outdent'' some lines containing certain
  91.           keywords (i.e.have auto-indenting but towards the left margin
  92.           instead of the right margin)?
  93.         o 5.30 Is there a repository for Vim macros?
  94.         o 5.31 If I have a mapping/abbreviation whose ending is the
  95.           beginning of another mapping/abbreviation, how do I keep the first
  96.           from expanding into the second one?
  97.         o 5.32 Modelines are cool but Vim's modeline support is too
  98.           restrictive. How can I improve it?
  99.         o 5.33 How can I use different .vimrc settings for different types
  100.           of files?
  101.         o 5.34 How can I search for tags when running Vim over a telnet
  102.           session?
  103.         o 5.35  [NEW] I get errors when trying to put scripts in my
  104.           mappings. Why?
  105.         o 5.36  [NEW] When I try to remove mappings in my autocommands, Vim
  106.           says my mappings don't exists. What's going on?
  107.    * 6 DOS-, WINDOWS-, WIN32-SPECIFIC QUESTIONS
  108.         o 6.1 Why does the Win32 version of Vim update the screen so slowly
  109.           on Windows 95?
  110.         o 6.2 So if the Win32 version updates the screen so slowly on
  111.           Windows 95 and the 16-bit DOS version updates the screen quickly,
  112.           why would I want to run the Win32 version?
  113.         o 6.3 And what about the 16-bit DOS version versus the Win32 version
  114.           on NT?
  115.         o 6.4 Why can't I paste into Vim when running Windows 95?
  116.         o 6.5 How do I type dead keys on Windows 95?
  117.         o 6.6 How do I type dead keys on Windows NT?
  118.         o 6.7 When will a real GUI version of Vim (gvim) for Win32 with
  119.           scrollbars, menus, pasting from the clipboard, and so on become
  120.           available?
  121.         o 6.8 On a Win32 machine, I'm using Vim to edit a symbolically
  122.           linked file on a Unix NFS file server. When I write the file, Vim
  123.           does not "write through" the symlink. Instead, it deletes the
  124.           symbolic link and creates a new file in its place. Why?
  125.         o 6.9 How do I copy text from Windows applications to the DOS
  126.           version of Vim?
  127.         o 6.10 Why does my Caps Lock affect all the keys characters for all
  128.           the keys instead of just the letters?
  129.         o 6.11 How do I change Vim's window size in Windows?
  130.    * 7 UNIX-SPECIFIC QUESTIONS
  131.         o 7.1 How do I turn off the message ``Thanks for flying Vim'' on
  132.           Unix stations?
  133.         o 7.2 How do I prevent <Ctrl-Z> from suspending Vim?
  134.         o 7.3 How can I make Vim faster on a Unix station?
  135.         o 7.4 In Unix, how do I make Vim more colorful?
  136.  
  137. 1 ABOUT THIS FAQ
  138.  
  139. 1.1 What versions of Vim does this FAQ cover?
  140.  
  141. At the time of its creation, version 4.0 was almost complete (3.21 was
  142. already available) therefore the FAQ covers mainly vim4-specific issues. But
  143. some answers may apply to Vim 3.0. There are no plans to make the FAQ
  144. ``backward compatible''. ;-) In particular, in various parts of the FAQ, you
  145. will see mentions of ``:h subject'' to get help about a specific subject.
  146. Although the help command works in 3.0, you cannot give it an argument.
  147.  
  148. 1.2 Who maintains this FAQ?
  149.  
  150. The current maintainer of this FAQ is Laurent Duperval. I can be reached at
  151. <laurent@grafnetix.com>. Please insert the keyword NOTSPAM in the Subject
  152. line of your message otherwise it may not reach me.
  153.  
  154. 1.3 Why him?
  155.  
  156. Well, I volunteered. You could have done it too, had you volunteered before
  157. me. ;-) Besides, after getting so much free and useful stuff off the 'Net, I
  158. decided to give something back in the form of this FAQ.
  159.  
  160. 1.4 Can I add to it?
  161.  
  162. Sure. Just send your questions (and answers!) to <laurent@grafnetix.com>.
  163. Comments and constructive criticism are always welcome.
  164.  
  165. 1.5 What are the restrictions on this FAQ?
  166.  
  167. Disclaimer: This article is provided as is without any express or implied
  168. warranties. While every effort has been taken to ensure the accuracy of the
  169. information contained in this article, the author / maintainer /
  170. contributors (take your pick) assume(s) no responsibility for errors or
  171. omissions, or for damages resulting from the use of the information
  172. contained herein.
  173.  
  174. This article is ⌐ Copyright 1996-1997 Laurent Duperval. You may distribute
  175. it as you wish provided this copyright and the above disclaimer is also
  176. provided. You may not sell it without express consent from the author. You
  177. may not distribute a modified version of this article without express
  178. consent from the author.
  179.  
  180.  
  181. 1.6  [CHANGED] Acknowledgements
  182.  
  183. The following people have contributed (from near or far) to the answers in
  184. this FAQ. Some of them may not even know about it.
  185.  
  186. Bram Moolenar <bram@vim.org>
  187. Sven Guckes <guckes@vim.org>
  188. Robert Webb <robertw@wormald.com.au>
  189. George V. Reilly <georger@halcyon.com>
  190. Tony Nugent <tonyn@sctnugen.ppp.gu.edu.au>
  191. Ingolf Markhof <markhof@ls12r.informatik.uni-dortmund.de>
  192. Stan Brown <stbrown@nacs.net>
  193. Raul Segura Acevedo <raul@turing.iquimica.unam.mx>
  194. Benjamin Elijah Griffin <eli@NetUSA.Net>
  195. Dr. Charles Campbell <cec@gryphon.gsfc.nasa.gov>
  196.  
  197. 2 GENERAL INFORMATION
  198.  
  199. 2.1 What is Vim?
  200.  
  201. Vim stands for Vi IMproved. It used to be Vi IMitation, but there are so
  202. many improvements that a name change was appropriate. Vim is a text editor
  203. which includes almost all the commands from the Unix program ``Vi'' and a
  204. lot of new ones. It is very useful for editing programs and other 7-bit or
  205. 8-bit ASCII text. All commands can be given with the keyboard. This has the
  206. advantage that you can keep your fingers on the keyboard and your eyes on
  207. the screen. For those who want it, there is mouse support and a GUI version
  208. with scrollbars and menus.
  209.  
  210. Vim is an editor, not a word processor. A word processor is used mainly to
  211. do layout of text. This means positioning it, changing the way it appears on
  212. output. More often than not, the final document is meant to be printed or
  213. typeset or what have you, in order to present it in a pleasing manner to
  214. others. Examples of word processors are Microsoft Word, WordPerfect,
  215. FrameMaker, and AmiPro.
  216.  
  217. An editor is simply for entering text. Any typesetting or laying out of the
  218. document is secondary. With an editor, one's main concern is entering text,
  219. not making the text look good. Examples of editors other than Vim and Vi are
  220. Emacs, Crisp, Brief, and xedit.
  221.  
  222. 2.2 Who wrote Vim?
  223.  
  224. Most of Vim was written by Bram Moolenar, with contributions from too many
  225. people to mention here. Try ``:h credits'' for a complete list.
  226.  
  227. Vim is based on Stevie, worked on by Tim Thompson, Tony Andrews and G.R.
  228. (Fred) Walter.
  229.  
  230. 2.3 Is Vim compatible with Vi?
  231.  
  232. Very. A special mode (``:set compatible'') makes Vim behave almost exactly
  233. like Vi.
  234.  
  235. 2.4 What are some of the improvements of Vim over Vi?
  236.  
  237. Here is a short summary. For more information, do ``:h diff''.
  238.  
  239. Multi-level undo
  240.      Allows you to set the number of times you can undo your changes in a
  241.      file buffer. You can also redo an undone change.
  242. Multiple windows and buffers
  243.      Each file can be displayed in its own window. You can move easily from
  244.      one window to another. Each file opened during a Vim session also has
  245.      an associated buffer and you can easily jump from one to the other.
  246. Repeat a series of commands.
  247.      Vim has a facility which allows you to record a sequence of typed
  248.      characters and repeat them any number of times.
  249. Flexible insert mode.
  250.      Vim allows you to use the arrow keys while in insert mode to move
  251.      around in the file. No more hitting <Esc>, moving around, then hitting
  252.      `i' or `a'.
  253. Visual mode.
  254.      You can highlight sections of text and execute operations on this
  255.      section of text only.
  256. Block operators
  257.      Allow selection and highlighting of rectangular blocks of text in order
  258.      do execute specific operations on them.
  259. Online help system.
  260.      You can easily find help on any aspect of using Vim. Help is displayed
  261.      in its own window.
  262. Command-line editing and history.
  263.      History allows you to use the arrow keys to repeat or search for a
  264.      command that has already been typed. Allows you to match the beginning
  265.      of a command with the beginning of another similar command in the
  266.      history buffer. You can also edit a command to correct typos or change
  267.      a few values.
  268. Command line completion.
  269.      Using the <Tab> key, you can complete commands, options, filenames,
  270.      etc. as needed.
  271. Horizontal scrolling.
  272.      Long lines can be scrolled horizontally (with or without the GUI).
  273. Text formatting.
  274.      With two keystrokes, you can format large sections of text, without the
  275.      use of external programs.
  276. Edit-compile-edit speedup.
  277.      You can compile within Vim and automatically jump to the location of
  278.      errors in the source code.
  279. Improved indenting for C programs
  280.      Vim gives you more control over how your C programs appear on screen.
  281. Searching for words in include files
  282.      Vim allows you to search for a match of the word under the cursor in
  283.      the current and included files.
  284. Word completion in Insert mode
  285.      Vim can complete words while you are typing, by matching the current
  286.      word with other similar words in the file.
  287. Automatic commands
  288.      Commands automatically executed when reading or writing a file, jumping
  289.      to another buffer, etc.
  290. Viminfo
  291.      Allows storing of the command line history, marks and registers in a
  292.      file to be read on startup.
  293. Mouse support
  294.      The mouse is supported in an xterm and for MS-DOS. It can be used to
  295.      position the cursor, select the visual area, paste a register, etc.
  296. Graphical User Interface (GUI) (Motif and Athena)
  297.      You can use the GUI and have access to a menu bar, scrollbar, etc. You
  298.      can also define your own menus as well as do many operations with the
  299.      mouse instead of the keyboard.
  300.  
  301. 2.5 What are the improvements of Vim 4 over Vim 3.x?
  302.  
  303. Here is a list of some of the improvements of Vim 4 over Vim 3. For a
  304. complete list, do ``:h vim_40''.
  305.  
  306.    * New on-line help system
  307.    * Command-line editing improved
  308.    * Improved indenting for C programs
  309.    * Searching for words in include files
  310.    * Word completion in Insert mode
  311.    * Automatic commands
  312.    * Text objects
  313.    * New Options
  314.    * Support for editing one-line paragraphs
  315.    * Usage of key names
  316.    * Viminfo
  317.    * Compilation improvements
  318.    * Tag support improved
  319.    * Improved (error) messages
  320.    * Swap file
  321.    * Mouse support
  322.    * Graphical User Interface (GUI)
  323.    * Support for Windows 95 and NT
  324.    * Vi compatibility improvements
  325.    * And more! (As if all that preceded wasn't reason enough to upgrade)
  326.  
  327. 2.6 What are the improvements of Vim 5.x over Vim 4.x?
  328.  
  329. Vim 5.0 is not officially out yet, but it will have syntax highlighting! And
  330. a command language! And much, much more!
  331.  
  332. 2.7 Is Vim free?
  333.  
  334. Vim is Charityware. There are no restrictions on using or copying Vim, but
  335. the author encourages you to make a donation to charity. A document
  336. explaining how to do so is included in the distribution. You are allowed to
  337. include Vim on a CD-ROM but you should send the author a copy. Please try
  338. ``:h copying''.
  339.  
  340. 3 RESOURCES
  341.  
  342.  
  343. 3.1  [CHANGED] Where can I learn more about Vim?
  344.  
  345. A mailing list is available for Vim. See the next question.
  346.  
  347. Vim does not have a newsgroup of its own. But the appropriate newsgroup to
  348. post to is comp.editors.
  349.  
  350. There is a Vim home page available at <URL:http://www.vim.org/>
  351.  
  352. More information can be found in
  353.  
  354.    * Eli's Vim Page <URL:http://www.netusa.net/~eli/src/vim.html>
  355.    * The Vi Lovers Home Page <URL:http://www.cs.vu.nl/~tmgil/vi.html>
  356.  
  357. There is a reference card which is only valid for version 5. It is available
  358. in Postscript by sending email to <raul@turing.iquimica.unam.mx>. Please
  359. specify a subject as follows:
  360.  
  361.    * ``send reference card'' for letter version
  362.    * ``send reference card a4'' for a4 version
  363.    * ``send reference card tex'' for the original LaTeX source
  364.  
  365. Oleg Raisky <olrcc@scisun.sci.ccny.cuny.edu> has created a reference guide
  366. for Vim and is available at
  367. <URL:http://scisun.sci.ccny.cuny.edu/~olrcc/vim/>. There are versions
  368. available for A4 and US Letter paper sizes.
  369.  
  370. 3.2 Is there a mailing list available?
  371.  
  372. There are three mailing lists for Vim (description to follow). You can join
  373. any of the lists by sending an empty mail message to the appropriate list
  374. handler. If for any reason, things don't work, contact <vim-help@vim.org>.
  375.  
  376.    * To (un)subscribe to the Vim Help list
  377.  
  378.      mail vim-(un)subscribe@vim.org
  379.  
  380.    * To (un)subscribe to the Vim Announcements list
  381.  
  382.      mail vim-announce-(un)subscribe@vim.org
  383.  
  384.    * To (un)subscribe to the Vim Development list
  385.  
  386.      mail vim-dev-(un)subscribe@vim.org
  387.  
  388. Each mailing list serves a different purpose and you should not crosspost
  389. between them. This is a brief description of each list:
  390.  
  391. <vim@vim.org>
  392.      For discussions about using existing versions of Vim: Useful mappings,
  393.      questions, answers, where to get a specific version, etc.
  394. <vim-dev@vim.org>
  395.      For discussions about changing Vim: New features, porting, etc.
  396. <vim-announce@vim.org>
  397.      Announcements about new versions of Vim and also beta-test versions and
  398.      ports to different systems. No discussions here, please.
  399.  
  400. If you have a question about the usage of Vim then please post it to
  401. comp.editorsor to the vim mailing list. Please note that if you send a
  402. message to a Vim mailing list but are not subscribed, your message will be
  403. discarded. You must subscribe in order to send mail to the mailing lists.
  404.  
  405. Do not send mail to the mailing lists for subscription or unsubscription.
  406. (The maintainer of the list hates that! So do the people subscribed to the
  407. lists.)
  408.  
  409. 3.3 Is there an archive available for the Vim mailing list?
  410.  
  411. There is an archive available for the announcements made on the vimannounce
  412. mailing list at <URL:http://www.findmail.com/listsaver/vimannounce.html>.
  413.  
  414. There is also a mail archive available by FTP if you need to check out old
  415. messages sent to one of the other lists. They are available at:
  416.  
  417. <URL:ftp://ftp.ii.uib.no/pub/vim/mail-archive/vim/maillist.html>
  418. <URL:ftp://ftp.ii.uib.no/pub/vim/mail-archive/vimdev/maillist.html>
  419. <URL:ftp://ftp.ii.uib.no/pub/vim/mail-archive/vimannounce/maillist.html>
  420.  
  421.  
  422. 3.4  [CHANGED] Where can I report bugs?
  423.  
  424. Well, you don't need to because there are none. ;-) But on the off chance
  425. that you may find an unexpected feature, you may send a description of it to
  426. the Vim Developmentlist. Take a look at
  427. <URL:http://www.vim.org/deve.html#bugreport> to see what type of information
  428. should be sent when making a bug report. There is also a script included
  429. with newer versions of Vim, which can be used to create a bug report.
  430.  
  431. We are looking for someone to take over the tasks of our previous bug
  432. maintainer. If you are interested, send a message to Bram <bram@vim.org>.
  433.  
  434. If you have patches that you would like to submit for approval and
  435. incorporation in future versions of Vim, you can send them to Bram
  436. <bram@vim.org>.
  437.  
  438. 3.5 Where can the FAQ be found?
  439.  
  440. This FAQ will be posted on a (hopefully) regular basis to the
  441. comp.editorsnewsgroup. The latest version can be found on
  442. <URL:http://www.grafnetix.com/~laurent/vim/faq.html>. It will also be
  443. mirrored at <URL:http://www.vim.org/faq/>. Eventually, it should make its
  444. way into news.answersand rtfm.mit.edu.
  445.  
  446. You can also find a searchable version of this and many more FAQs at the
  447. Hypertext FAQ Archiveat <URL:http://www.landfield.com/faqs/>.
  448.  
  449. 3.6 What if I don't find an answer in this FAQ?
  450.  
  451. This FAQ covers mainly Vim-specific questions. You may find more information
  452. suitable for most Vi clones by reading the Vi FAQ. It is posted regularly on
  453. comp.editors. You can also find a copy at
  454. <URL:ftp://rtfm.mit.edu/pub/usenet-by-group/comp.editors>.
  455.  
  456. Please note that although I maintain the FAQ, I am not the best resource to
  457. answer questions about Vim. If you send a question about using Vim diretly
  458. to me, 9 times out of 10 I will redirect you to the Vim mailing listor to
  459. comp.editors. So you might as well send your questions directly there since
  460. you're liable to get a more accurate and useful response than I could give
  461. you.
  462.  
  463. 4 AVAILABILITY
  464.  
  465.  
  466. 4.1  [CHANGED] What is the latest version of Vim?
  467.  
  468. The latest version is 4.6. The latest beta release is 5.0w (as of February
  469. 8, 1998).
  470.  
  471. 4.2 Where can I find the latest version of Vim?
  472.  
  473. The main archive for the latest versions of Vim is
  474. <URL:ftp://ftp.oce.nl/pub/vim> The directory structure:
  475.  
  476.         /pub/vim/amiga
  477.         /pub/vim/atari
  478.         /pub/vim/beta-test
  479.         /pub/vim/os2
  480.         /pub/vim/pc
  481.         /pub/vim/unix
  482.  
  483. The latest public release can be found in the atari, amiga, os2, pc, and
  484. unix directories. The latest beta-test versions can be found in the
  485. beta-test subdirectories.
  486.  
  487. For a complete and updated list of current FTP sites, please refer to
  488. <URL:http://www.vim.org/dist.html>.
  489.  
  490.  
  491. 4.3  [CHANGED] What platform does it run on?
  492.  
  493. Vim should compile with no problems on most flavors of Unix and on DOS,
  494. OS/2, Ataris, Amigas, Windows 95, Windows NT, BeOS and VMS. Binaries for
  495. other systems are also available. A complete list of supported platforms and
  496. available binaries can be found at <URL:http://www.vim.org/dist.html>
  497.  
  498.  
  499. 4.4  [CHANGED] What do I need to compile and install Vim?
  500.  
  501. Unless you are on a Unix station, you may not need to compile Vim since
  502. there are various binaries available for Windows, Windows 95, Windows NT,
  503. DOS, OS/2 and Amiga (please see <URL:http://www.vim.org/dist.html#binaries>.
  504. But if you need to compile it, you must have a C compiler and a make
  505. utility. Most commercial C compilers come bundled with a make utility, so if
  506. you've got one of those, you're in luck. If you need a compiler or if your
  507. make utility doesn't like the Makefiles provided with Vim, you can get the
  508. GNU C compiler and GNU make at <URL:ftp://prep.ai.mit/edu/pub/gnu> and its
  509. mirrors. At that same site, you can also find sed, binutils, and other GNU
  510. tools (such as gzip) which can be useful on certain systems. For DOS
  511. systems, you can look in <URL:ftp://ftp.coast.net/SimTel/msdos/>.
  512.  
  513. If you plan on compiling the GUI version of Vim under Unix, you must have
  514. some kind of widget library. One of these three should suffice:
  515.  
  516. Motif libraries
  517.      These libraries are commercial but are distributed with a number of
  518.      operating systems. You can find out how to purchase it by going to
  519.      <URL:http://www.rdg.opengroup.org/>.
  520. Athena libraries
  521.      This is a freely available widget set which is included in the X11
  522.      distribution. This is a no frills library which implements a number of
  523.      widgets that are necessary when building a GUI. Various other similar
  524.      libraries have been built from the Athena widget set. These variations
  525.      allow a 3D look and a NextStep look. These variations are not part of
  526.      the X11 distribution. The X11 distribution is available at
  527.      <URL:ftp://ftp.x.org/>.
  528. Lesstif
  529.      This is a free Motif clone. It is available at
  530.      <URL:http://www.lesstif.org/>.
  531.  
  532. 5 TIPS AND TECHNIQUES
  533.  
  534. Note: This section contains various macros written in Vim's macro language,
  535. called ``<> notation'' (you can find the description by doing
  536. ``:h key_notation''). All macros should be entered as is in your .vimrc file
  537. or on Vim's command line. You should even be able to cut and paste the
  538. information. This is a short description of the language:
  539.  
  540.    * Any printable characters are typed directly, except backslash and '<'.
  541.    * A backslash is represented with ``\\'', double backslash.
  542.    * A real '<' is represented with ``\<''.
  543.    * ``<key>'' means the special key typed. A few examples:
  544.  
  545.                 <Esc>                Escape key
  546.                 <C-G>                CTRL-G
  547.                 <Up>                 cursor up key
  548.                 <C-LeftMouse>        Control- left mouse click
  549.                 <S-F11>              Shifted function key 11
  550.                 <M-a>                Meta- a  ('a' with bit 8 set)
  551.                 <M-A>                Meta- A  ('A' with bit 8 set)
  552.                 <t_kd>               "kd" termcap entry (cursor down key)
  553.  
  554. If you want to use this notation in Vim, you have to remove the 'B' flag
  555. from 'cpoptions' and make sure the '<' flag is excluded. The default values
  556. for cpoptions should work fine.
  557.  
  558.         :set cpo=ceFs
  559.  
  560. For mapping, abbreviation and menu commands you can then copy-paste the
  561. examples and use them directly. Or type them literally, including the '<'
  562. and '>' characters. This does NOT work for other commands, like ``:set'' and
  563. ``:autocmd''!
  564.  
  565. Other tips, not appearing in this FAQ, can be found by doing ``:h tips''.
  566.  
  567. 5.1 How do I use the help files?
  568.  
  569. Help can be found for all functions of Vim. In order to use it, use ``:h''.
  570. This will bring you to the main help page. On that first page, you will find
  571. explanations on how to move around. Basically, you move around in the help
  572. pages the same way you would in a read-only document. You can jump to
  573. specific subjects by using tags. This can be done in two ways:
  574.  
  575.    * Use the ``<Ctrl-]>'' command while standing on the name of a command or
  576.      option. This only works when the tag is a keyword. ``<Ctrl-LeftMouse>''
  577.      and ``g<LeftMouse>'' work just like ``<Ctrl-]>''.
  578.    * use the ``:ta subject'' command. This works with all characters.
  579.  
  580. Use ``<Ctrl-T>'' to jump back to previous positions in the help files. Use
  581. ``:q'' to close the help window.
  582.  
  583. If you want to jump to a specific subject on the help pages, use
  584. ``:h {subject}''. If you don't know what to look for, try ``:h index'' to
  585. get a list of all available subjects. Use the standard search keys to locate
  586. the information you want. By version 6 or 7, we should have a search engine
  587. available. ;-)
  588.  
  589.  
  590. 5.2 Why is a backup file written even if I set nobackup?
  591.  
  592. In order to keep Vim from writing a backup, you must also do
  593. ``:set nowritebackup''.
  594.  
  595. 5.3 How can I keep Vim from beeping all the time?
  596.  
  597. Well, you can use ``set noerrorbells" but it does not turn off the bell for
  598. all cases. It only makes a difference for error messages; the bell will be
  599. always be used for a lot of errors without a message (e.g., hitting <Esc> in
  600. Normal mode).
  601.  
  602. If you want Vim to stop beeping then all you need is ``:set vb'' which tries
  603. to do a screen flash rather than an audible beep. Some terminals can't do
  604. screen flashes, but if yours does and you don't want it to flash or beep
  605. then use ``:set vb t_vb=''.
  606.  
  607. 5.4 How do I map the Tab key?
  608.  
  609. :map <Tab> right-hand-side
  610.  
  611. 5.5 How do I map the Esc key?
  612.  
  613. On some keyboards the escape key is not placed very well. It's either part
  614. of the numeric block or it can be a small button (as with some Macintosh
  615. keyboards). But do not despair - make your own escape key! You can map one
  616. of the commands keys you do not need to Esc. Example: map CTRL-O to ESC:
  617.  
  618. :map <C-O> <Esc>
  619.  
  620. 5.6 How do I tell Vim where the helpfile is?
  621.  
  622. To tell Vim where to find the help file, ``:set helpfile'' to the correct
  623. value, i.e., including the full path. As with most options you can
  624. abbreviate ``helpfile'' to ``hf''. On the other hand, if your VIM
  625. environment variable points to the directory containing the help file, vim
  626. will find the help file with no need to ``:set hf=''.
  627.  
  628.  
  629. 5.7 How do I get back to the exact position within a line I have marked with
  630. 'a'?
  631.  
  632. Use ```a'' (that's a backtick!). If the backtick is awkwardly placed on your
  633. keyboard, the following maping may be useful to you:
  634.  
  635. map ' `
  636.  
  637. 5.8 How do I read in the output of a command?
  638.  
  639. Use ``:r!command''.
  640.  
  641. 5.9 Why can't I abbreviate ``'xy''?
  642.  
  643. The abbreviation consists of a non-id character followed by two id
  644. characters, which does not satisfy either category of a ``full-id''.
  645. However, ``_ps'' and ``'p'' will work.
  646.  
  647.  
  648. 5.10 How do I jump to the beginning/end of the highlighted text?
  649.  
  650. The command 'o' will jump to the beginning/end of the highlighted text.
  651.  
  652.  
  653. 5.11 Why does completion of ``:set n'' not show negated settings, e.g.,
  654. ``noautoindent''? Completion of ``:set no'' seems to work.
  655.  
  656. The thing is that the ``no'' is not actually part of the option's name; the
  657. name comes after that. So after ``no'', Vim knows to complete any boolean
  658. setting name (starts the completion just after the ``no'', which is not part
  659. of the name). After ``n'', Vim will complete all setting names starting with
  660. ``n''. It would be a bummer if you wanted to complete ``number'', but had to
  661. wade through all the boolean option names with ``no'' prepended too.
  662.  
  663. 5.12 Is there a command to remove any or all digraphs?
  664.  
  665. No. The digraphs table is defined at compile time. You can only add new
  666. ones. Adding a command to remove digraphs is on the todo list.
  667.  
  668. 5.13 How do I use a spell checker with Vim?
  669.  
  670. You can call a non-interactive spell checker from Vim without a problem. A
  671. function to look up a word is included with the command ``K''. So what you
  672. do is get such a spell checker, then you issue the command
  673. ``:set keywordprg=ispell'', and then hit ``K'' on the word you want to look
  674. up, i.e., check. If you need to give options to your spell checker command,
  675. escape all spaces with a backslash.
  676.  
  677. If you need to use an interactive spell checker and are working with Unix,
  678. you can try this approach proposed by Ives Aerts <ives@sonycom.com>:
  679.  
  680. noremap ;ispell :%! ispell-filter<CR><C-L>
  681.  
  682. where ispell-filter is the following script:
  683.  
  684. #!/bin/sh
  685. #
  686. # This little script can be used to run ispell on stdin, returning the result
  687. # through stdout.
  688. # It can be used from VI like this (or map it to a key sequence):
  689. # :%! ~/bin/ispell-filter
  690. #
  691. cat > /tmp/tmp.$$
  692. ispell $* /tmp/tmp.$$ < /dev/tty > /dev/tty
  693. cat /tmp/tmp.$$
  694. rm -f /tmp/tmp.$$
  695.  
  696. or this macro proposed by Dr. Charles E. Campbell Jr.
  697. <cec@gryphon.gsfc.nasa.gov>:
  698.  
  699. map #fi :w<CR>:!ispell %<CR>:e %<CR>
  700.  
  701.  
  702. 5.14 Can I copy the character above the cursor to the current cursor
  703. position?
  704.  
  705. In Insert mode, you can copy the character above the cursor to the current
  706. cursor position by typing <Ctrl-Y>. The same can be done with the characters
  707. below the cursor by using <Ctrl-E>. This is neat when you need to duplicate
  708. partial lines without going through the process of yanking a line and
  709. deleting the unwanted part.
  710.  
  711. 5.15 How do I remove empty lines?
  712.  
  713. To remove all empty lines do ``:g/^$/d''.
  714.  
  715. ``:g/[ <Tab>]*$/d'' deletes lines that aren't blank but look it, too.
  716.  
  717.  
  718. 5.16 How do I reduce a range of empty lines into one line only?
  719.  
  720. You can try ``:v/./.,/./-1join''. Note that this will give an error message
  721. if the empty lines are at the end of the file. To correct this, use the
  722. following mapping instead:
  723.  
  724. map  _b  GoZ<Esc>:g/^[ <Tab>]*$/,/[^ <Tab>]/-j<CR>Gdd
  725.  
  726.  
  727. 5.17 How can I paste large amounts of text between two running sessions of
  728. Vim?
  729.  
  730. If you are using the GUI version of Vim, with the Motif or Athena interface,
  731. you can actually cut and paste between the two, and text will be copied
  732. exactly; that is, tabs will not change into spaces, and if you copy a
  733. rectangular block, then that is what you will paste too!
  734.  
  735. Otherwise, in a terminal Vim, use these mappings:
  736.  
  737. " _Y: Yank the highlighted block of text (or a single line) to a tmp file.
  738. " _P: Put the text yanked with \_Y (possibly in another invocation of Vim).
  739. "
  740. nmap    _Y      :.w! ~/.vi_tmp<CR>
  741. vmap    _Y      :w! ~/.vi_tmp<CR>
  742. nmap    _P      :r ~/.vi_tmp<CR>
  743.  
  744. Now you just highlight the area you want to copy with ``V'' etc, and yank it
  745. with ``_Y''. Then you can paste it in another Vim with ``_P''.
  746.  
  747. 5.18 Can I use compressed versions of the help files?
  748.  
  749. For those that are really short on disk space, you can compress the help
  750. files and still be able to view them with Vim. This example assumes you have
  751. gzip on your system. You do have it, don't you? :-) If not, you will need to
  752. adapt it to work with a different compression utility.
  753.  
  754. 1.   Compress all the help files: ``gzip doc/*.txt''.
  755. 2.   Edit doc/vim_tags (doc/tags in 5.0) and do
  756.      :%s=\.txt<Tab>/=.txt.gz<Tab>/=
  757. 3.   Add these lines to your .vimrc:
  758.  
  759.              set helpfile=<dirname>/vim_help.txt.gz
  760.              autocmd BufReadPost *.txt.gz set bin | '[,']!gunzip
  761.              autocmd BufReadPost *.txt.gz set nobin
  762.              set cmdheight=2
  763.  
  764. Where ``dirname'' is the directory where the help files are. If you already
  765. have included autocommands to edit ``.gz'' files you should omit the two
  766. ``autocmd'' lines. Note that you must ``set nocompatible'' for this to work
  767. in Vim 5.0.
  768.  
  769. 5.19 How come I can't set option ``xxxx''?
  770.  
  771. Some options are compiled into Vim. If you want to enable these options,
  772. then you must modify the feature.h file. You can see what compile-time
  773. options are available by looking at the version number (:ver). It will give
  774. you something like this:
  775.  
  776. Compiled with (+) or without (-):
  777. +autocmd +builtin_terms +cindent -compatible +digraphs -emacs_tags +fork()
  778. -GUI +insert_expand -langmap +lispindent -rightleft +smartindent -terminfo
  779. +viminfo +writebackup +X11
  780.  
  781. As the example shows, all options compiled into the Vim binary are preceded
  782. by a '+'. All options that are not compiled in are preceded by a '-'. All
  783. options that do not appear in this list do not need to be compiled in.
  784.  
  785. 5.20 How do I format a block of C code?
  786.  
  787. To format C code, use = instead of Q. Try ``:h C_indenting'' to get more
  788. information on controlling the way your code is formatted.
  789.  
  790.  
  791. 5.21 How do I put a command onto the command history without executing it?
  792.  
  793. You need only end the input with <ESC> (not <Ctrl-V><Esc>).
  794.  
  795.  
  796. 5.22 Why do I hear a beep (why does my window flash) about 1 second after I
  797. hit the Escape key?
  798.  
  799. This is normal behavior. If your window flashes, then you've got the visual
  800. bell on. Otherwise, you should hear a beep.
  801.  
  802. Vim (and most, if not all, other implementations of Vi) needs a timeout to
  803. tell the difference between a simple escape and, say, a cursor key sequence.
  804. When you press a key in normal mode (and even in insert mode) and that key
  805. is the beginning of a mapping, Vim waits a certain amount of time to see if
  806. the rest of the mapping sequence follows. If the mapping sequence is
  807. completed before a given timeout period, the mapping for that sequence of
  808. keys is applied. If you interrupt the mapping, the normal actions associated
  809. with the keys are executed.
  810.  
  811. For example, if you have a mapping defined as ``:imap vvv Vim is great!!''
  812. and you type ``vvv'' quickly, the ``Vim is great!!'' will be inserted into
  813. your text. But if you type ``vv v'' then that is what will put into your
  814. text. This is also true if you type ``vvv'' too slowly where ``too slowly''
  815. is longer than the value for the timeout option. Setting the timeout option
  816. to a larger value can help alleviate problems that appear when using
  817. function keys over a slow line. Do ``:h timeout'' for more information on
  818. using this option and its cohorts.
  819.  
  820.  
  821. 5.23 How do I make the 'c' and 's' commands display a '$' instead of
  822. deleting the characters I'm changing?
  823.  
  824. Add ``:set cpoptions=ces$'' to your .vimrc. Vi-compatible behavior can be
  825. controlled like this. Do ``:help cpoptions'' for more information.
  826.  
  827.  
  828. 5.24 How do I add a line before each line with ``pattern'' in it?
  829.  
  830. 1.   Yank the line using Y
  831. 2.   Insert the line with ``:g/pattern/put!''
  832.  
  833.  
  834. 5.25 How can I delete the newline which is followed by a given character,
  835. such as ``|''?
  836.  
  837. Look at this problem this way: If there is a newline before the character
  838. then the character is the first character of the next line, i.e., it follows
  839. the start-of-line meta character (^). So the command to use is to look
  840. globally for all lines starting with the given character and the command to
  841. use on these lines is ``go back one line'' and ``join'' which will remove
  842. the next newline. The resulting command is:
  843.  
  844. :g/^|/-1join
  845.  
  846.  
  847. 5.26 How do I use the join command within a range of lines that ends with
  848. ``*'' and begins with the previous ``|''?
  849.  
  850. :?^|?,/*$/join
  851.  
  852.  
  853. 5.27 How do I map/unmap an abbreviation or a map!ed key sequence?
  854.  
  855. In either case, ``:set paste'' will do the trick. Use ``:set nopaste'' to
  856. return to normal.
  857.  
  858. For map!ed key sequences, you have a these tricks also;
  859.  
  860.    * After typing the first key of the key sequence, pause about 1 second
  861.      before typing the rest of the sequence.
  862.    * Type <Ctrl-V> before typing the first key in the key sequence.
  863.  
  864. Normally, you shouldn't need these tricks. When ``:unmap'' finds an argument
  865. that is not a ``from'' part, it looks for a matching ``to'' part and unmaps
  866. that one.
  867.  
  868.  
  869. 5.28 When I use my arrow keys, Vim changes modes, inserts weird characters
  870. in my document but doesn't move the cursor properly. What's going on?
  871.  
  872. There are a couple of things that could be going on: either you are using
  873. Vim over a slow connection or Vim doesn't understand the key sequence that
  874. your keyboard is generating.
  875.  
  876. If you are working over a slow connection (such as a 2400 bps modem), you
  877. can try to set timeout or ttimeout. These options, combined with timeoutlen
  878. and ttimeoutlen, may fix the problem. Do ``:h timeout'' and
  879. ``:h timeoutlen'' for a better description on how to use them.
  880.  
  881. The preceding procedure will not work correctly if your terminal sends key
  882. codes that Vim does not understand. In this situation, your best option is
  883. to map your key sequence to a matching cursor movement command and save
  884. these mappings in a file. You can then ``:source'' the file whenever you
  885. work from that terminal.
  886.  
  887.  
  888. 5.29 How do I ``auto-outdent'' some lines containing certain keywords
  889. (i.e.have auto-indenting but towards the left margin instead of the right
  890. margin)?
  891.  
  892. For example (make sure you adapt the example to your personal needs):
  893.  
  894. for k=1:10,
  895.   stuff
  896.   ..
  897.   end;
  898.   ^^^ This word marks the end of a loop and I'd like it to be
  899.       automatically outdented to the same column as the word
  900.       for.
  901.  
  902. The following macro will do this (from Raul Segura Acevedo
  903. <raul@turing.iquimica.unam.mx>):
  904.  
  905. :iab  end; <C-D>end;
  906.  
  907. This abbreviation takes effect when you type a non-keyword character after
  908. it (``;'', ``!'', space, tab, <Esc>, <CR>, etc). You can load this macro
  909. automatically using the following autocommands:
  910.  
  911. au!  BufEnter   *.f,*.ff        iab     end;    <C-D>end;
  912. au!  BufLeave   *.f,*.ff        iunab   end;
  913.  
  914. 5.30 Is there a repository for Vim macros?
  915.  
  916. As a matter of fact, there is. You can find the latest versions of
  917. contributed macros at
  918. <URL:http://www.grafnetix.com/~laurent/vim/macros.html>. At the time this
  919. version of the FAQ was updated, the following macros were available:
  920.  
  921.    * A file browser
  922.    * Some macros to edit HTML code
  923.    * Macros to deal with numbered lists
  924.    * A Tic Tac Toe game
  925.  
  926.  
  927. 5.31 If I have a mapping/abbreviation whose ending is the beginning of
  928. another mapping/abbreviation, how do I keep the first from expanding into
  929. the second one?
  930.  
  931. Instead of using :map lhs rhs, use :noremap lhs rhs. For abbreviations, use
  932. noreabbrev lhs rhs. The ``nore'' prefix prevents the mapping or abbreviation
  933. from being expanded again. You must be using version 4.5 or greater.
  934.  
  935.  
  936. 5.32 Modelines are cool but Vim's modeline support is too restrictive. How
  937. can I improve it?
  938.  
  939.