荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: jjksam (sh, bash), 信区: Linux
标  题: vim FAQ                                jjksam
发信站: 荔园晨风BBS站 (Sat Mar 23 10:14:09 2002), 站内信件

The VIM FAQ

URL(for now):       http://www.vim.org/faqnew/
URL (after reqrite):http://www.vim.org/faq/
Created:Fri Feb 20 00:00:00 CEST 1997
Last update:Mon Jun 05 12:00:00 MET DST 2000
Maintainer:Sven Guckes guckes@vim.org


FAQ short description: This text contains answers to FAQs (Frequently Asked
Questions) about the editor "VIM" (Vi IMproved), a vi clone for many
operating systems.



VIM FAQ - Chapter 0 - Contents

0.0 ABOUT THIS FAQ
0.1 What is this FAQ about?
0.2 Who maintains this FAQ?
0.3 How can I add to this FAQ?
0.4 What are the restrictions on this FAQ?

Description

What is Vim?
What platform does it run on?


Features

How compatible are Vi and Vim?
What are the improvements of Vim over Vi?
What are the new features of Vim-5?


Distribution:

Binaries/Source

Where can I get Vim?
What is the latest version of Vim?
Where can I find the latest version of Vim?


Usage:

Getting started

How do I use this editor?


Abbreviations
Mappings
Macros and Mappings
Text Objects
Angle Notation
Visual Text
Filters
Copy&Paste
Substitution
Text Formatting
Number Prefix
Jumps
Registers





Development:

Author and Developers

Who wrote Vim?


Code History

Conversation:

IRC channel #vim
MailLists

Is there a mailing list available?
Is there an archive available for the Vim mailing list?


Newsgroups

Where can I send my questions about Vim?


Copyright/Status

Is Vim free?
Can I copy Vim?
Can I bundle Vim with my work?



3.4 Where can I report bugs? 3.5 Where can the FAQ be found? 5 TIPS AND
TECHNIQUES 5.1 How do I use the help files? 5.2 Why is a backup file written
even if 5.4 How do I map the Tab key? 5.5 How do I map the Esc key? 5.6 How
do I tell Vim where the helpfile is? 5.7 How do I get back to the exact
position within a line I have marked with 'a'? 5.8 How do I read in the
output of a command? 5.9 Why can't I abbreviate ``'xy''? 5.10 How do I jump
to the beginning/end of the highlighted text? 5.11 Why does completion of ``:
set n'' not show negated settings, e.g., ``noautoindent''? Completion of ``:set
 no'' seems to work. 5.12 Is there a command to remove any or all digraphs? 5.
13 How do I use a spell checker with Vim? 5.14 Can I copy the character above
the cursor to the current cursor position? 5.15 How do I remove empty lines?
5.16 How do I reduce a range of empty lines into one line only? 5.17 How can
I paste large amounts of text between two running sessions of Vim? 5.18 Can I
use compressed versions of the help files? 5.19 How come I can't set option
``xxxx''? 5.20 How do I format a block of C code? 5.21 How do I put a command
onto the command history without executing it? 5.22 Why do I hear a beep (why
does my window flash) about 1 second after I hit the Escape key? 5.23 How do
I make the 'c' and 's' commands display a '$' instead of deleting the
characters I'm changing? 5.24 How do I add a line before each line with
``pattern'' in it? 5.25 How can I delete the newline which is followed by a
given character, such as ``|''? 5.26 How do I use the join command within a
range of lines that ends with ``*'' and begins with the previous ``|''? 5.27
How do I map/unmap an abbreviation or a map!ed key sequence? 5.28 When I use my
 arrow keys, Vim changes modes, inserts weird characters in my document but
doesn't move the cursor properly. What's going on? 5.29 How do I
``auto-outdent'' some lines containing certain keywords (i.e.have
auto-indenting but towards the left margin instead of the right margin)? 5.30
Is there a repository for Vim macros? 5.31 If I have a mapping/abbreviation
whose ending is the beginning of another mapping/abbreviation, how do I keep
the first from expanding into the second one? 5.32 Modelines are cool but Vim's
 modeline support is too restrictive. How can I improve it? 5.33 How can I
use different .vimrc settings for different types of files? 5.34 How can I
search for tags when running Vim over a telnet session?

Operating System Specific WQuestions DOS-, WINDOWS-, WIN32-SPECIFIC QUESTIONS

DOS | Windows 32bit | Unix



6.1 Why does the Win32 version of Vim update the screen so slowly on Windows
95?
6.2 So if the Win32 version updates the screen so slowly on Windows 95 and
the 16-bit DOS version updates the screen quickly, why would I want to run
the Win32 version?
6.3 And what about the 16-bit DOS version versus the Win32 version on NT?
6.4 Why can't I paste into Vim when running Windows 95?
6.5 How do I type dead keys on Windows 95?
6.6 How do I type dead keys on Windows NT?
6.7 When will a real GUI version of Vim (gvim) for Win32 with scrollbars,
menus, pasting from the clipboard, and so on become available?
6.8 On a Win32 machine, I'm using Vim to edit a symbolically linked file on a
Unix NFS file server. When I write the file, Vim does not "write through" the
symlink. Instead, it deletes the symbolic link and creates a new file in its
place. Why?
6.9 How do I copy text from Windows applications to the DOS version of Vim?
6.10 Why does my Caps Lock affect all the keys characters for all the keys
instead of just the letters?
6.11 How do I change Vim's window size in Windows?

7 UNIX-SPECIFIC QUESTIONS

7.1 How do I turn off the message ``Thanks for flying Vim'' on Unix stations?
7.2 How do I prevent <Ctrl-Z> from suspending Vim?
7.3 How can I make Vim faster on a Unix station?
7.4 In Unix, how do I make Vim more colorful?

Scope of FAQ
Q: What versions of Vim does this FAQ cover?
A: The VIM FAQ mostly covers answers to questions about vim-4.6 (the last
release of vim-4) and alpha versions of vim-5. It also contains some FAQs about
 vim-3 which seems to be widely used.

Q: Can I add something to the FAQ?
A: Definitely! Send all your comments, hints, improved answers to the FAQ
maintaner!
FAQ Maintainer
Q: Who maintains the VIM FAQ?
A: The maintainer of the VIM FAQ is Sven Guckes guckes@vim.org - please use
this address to send questions. Thanks!
[971013]

Disclaimer
Q: What are the restrictions on this FAQ?
A:

This article is provided as is without any express or implied warranties. While
 every effort has been taken to ensure the accuracy of the information
contained in this article, the author / maintainer / contributors (take your
pick) assume(s) no responsibility for errors or omissions, or for damages
resulting from the use of the information contained herein.

This article is ? Copyright 1996-1997 Laurent Duperval. You may distribute it
as you wish provided this copyright and the above disclaimer is also provided.
 You may not sell it without express consent from the author. You may not
distribute a modified version of this article without express consent from
the author.

(We need to talk, Laurent!)

All credits are given on the VIM Users Page:

http://www.vim.org/user.html

Bram Moolenar <mool@oce.nl >
Sven Guckes <guckes@math.fu-berlin.de >
Robert Webb <robertw@wormald.com.au >
George V. Reilly <georger@halcyon.com >
Tony Nugent <tonyn@sctnugen.ppp.gu.edu.au >
Ingolf Markhof <markhof@ls12r.informatik.uni-dortmund.de >
Stan Brown <stbrown@nacs.net >
Raul Segura Acevedo <raul@hplara.iquimica.unam.mx >
Benjamin Elijah Griffin <eli@NetUSA.Net >

2 GENERAL INFORMATION

2.1 What is Vim?

Vim = Vi IMproved

Vim stands for "Vi IMproved". It used to be "Vi IMitation", but there are so
many improvements over the standard Vi that a name change was appropriate.

Vim Purpose

Vim is a text editor which includes almost all the commands from the Unix
program Vi and a lots of new ones. It is very useful for editing programs and
other 7-bit or 8-bit ASCII text.



The main idea of this editor is to give powerful and general purpose commands
access to all commands for all kinds of keyboards, and thus All commands can be
 given with the keyboard. This has the advantage that you can keep your fingers
 on the keyboard and your eyes on the screen. For those who want it, there is
mouse support and a GUI version with scrollbars and menus.

Text Editor vs Word Processor

Vim is an editor, not a word processor. But are the differences between the
two?

Well, an editor is simply for entering text. You should understand text as in
"the set of characters representing the values from zero to 255." And please
remember that "characters" are always an interpretation of those numbers, ie
the dots that appear on your screen depend on the current "font".

Any typesetting or laying out of the document usually is secondary. With an
editor, one's main concern is entering text, not making the text look good.
Examples of editors other than Vim and Vi are Emacs, Crisp, Brief, and xedit.

A word processor is used mainly to do layout of text. This means positioning
it, changing the way it appears on output. More often than not, the final
document is meant to be printed or typeset or what have you, in order to
present it in a pleasing manner to others. Examples of word processors are
Microsoft Word, WordPerfect, FrameMaker, and AmiPro.

2.2 Who wrote Vim?

Most of Vim was written by Bram Moolenar, with contributions from too many
people to mention here. Try ``:h credits'' for a complete list.

Vim is based on Stevie, worked on by Tim Thompson, Tony Andrews and G.R. (Fred)
 Walter.

2.3 Is Vim compatible with Vi?

Very. A special mode (``:set compatible'') makes Vim behave almost exactly like
 Vi.

2.4 What are some of the improvements of Vim over Vi?

Here is a short summary. For more information, do ``:h diff''.

Multi-level undo
Allows you to set the number of times you can undo your changes in a file
buffer. You can also redo an undone change.
Multiple windows and buffers
Each file can be displayed in its own window. You can move easily from one
window to another. Each file opened during a Vim session also has an associated
 buffer and you can easily jump from one to the other.
Repeat a series of commands.
Vim has a facility which allows you to record a sequence of typed characters
and repeat them any number of times.
Flexible insert mode.
Vim allows you to use the arrow keys while in insert mode to move around in the
 file. No more hitting <Esc>, moving around, then hitting `i' or `a'.
Visual mode.
You can highlight sections of text and execute operations on this section of
text only.
Block operators
Allow selection and highlighting of rectangular blocks of text in order do
execute specific operations on them.
Online help system.
You can easily find help on any aspect of using Vim. Help is displayed in its
own window.
Command-line editing and history.
History allows you to use the arrow keys to repeat or search for a command that
 has already been typed. Allows you to match the beginning of a command with
the beginning of another similar command in the history buffer. You can also
edit a command to correct typos or change a few values.
Command line completion.
Using the <Tab> key, you can complete commands, options, filenames, etc. as
needed.
Horizontal scrolling.
Long lines can be scrolled horizontally (with or without the GUI).
Text formatting.
With two keystrokes, you can format large sections of text, without the use
of external programs.
Edit-compile-edit speedup.
You can compile within Vim and automatically jump to the location of errors
in the source code.
Improved indenting for C programs
Vim gives you more control over how your C programs appear on screen.
Searching for words in include files
Vim allows you to search for a match of the word under the cursor in the
current and included files.
Word completion in Insert mode
Vim can complete words while you are typing, by matching the current word
with other similar words in the file.
Automatic commands
Commands automatically executed when reading or writing a file, jumping to
another buffer, etc.
Viminfo
Allows storing of the command line history, marks and registers in a file to be
 read on startup.
Mouse support
The mouse is supported in an xterm and for MS-DOS. It can be used to position
the cursor, select the visual area, paste a register, etc.
Graphical User Interface (GUI) (Motif and Athena)
You can use the GUI and have access to a menu bar, scrollbar, etc. You can also
 define your own menus as well as do many operations with the mouse instead
of the keyboard.

2.5 What are the improvements of Vim 4 over Vim 3.x?

Here is a list of some of the improvements of Vim 4 over Vim 3. For a
complete list, do ``:h vim_40''.

New on-line help system
Command-line editing improved
Improved indenting for C programs
Searching for words in include files
Word completion in Insert mode
Automatic commands
Text objects
New Options
Support for editing one-line paragraphs
Usage of key names
Viminfo
Compilation improvements
Tag support improved
Improved (error) messages
Swap file
Mouse support
Graphical User Interface (GUI)
Support for Windows 95 and NT
Vi compatibility improvements
And more! (As if all that preceded wasn't reason enough to upgrade)



2.6 What are the improvements of Vim 5.x over Vim 4.x?

Vim 5.0 is not officially out yet, but it will have syntax highlighting! And
a command language!

2.7 Is Vim free?

Vim is Charityware. There are no restrictions on using or copying Vim, but
the author encourages you to
make a donation to charity. A document explaining how to do so is included in
the distribution. You are allowed to include Vim on a CD-ROM but you should
send the author a copy. Please try ``:h copying''.

3 RESOURCES

3.1 Where can I learn more about Vim?

A mailing list is available for Vim. See the next question . Vim does not
have a newsgroup of its own. But the appropriate newsgroup to post to is comp.
editors . There is also a Vim home page available at <URL:http://www.math.
fu-berlin.de/~guckes/vim/ >. More information can be found in

Eli's Vim Page <URL:http://www.netusa.net/~eli/src/vim.html >
The Vi Lovers Home Page <URL:http://www.cs.vu.nl/~tmgil/vi.html >

3.2 Is there a mailing list available?

There are three mailing lists for Vim (description to follow). You can join any
 of the lists by sending an empty mail message to the appropriate list handler.
 If for any reason, things don't work, contact vim- help@babayaga.math.
fu-berlin.de.

To (un)subscribe to the Vim Help list.

mail vim-(un)subscribe@babayaga.math.fu-berlin.de


To (un)subscribe to the Vim Announcements list

mail vim-announce-(un)subscribe@babayaga.math.fu-berlin.de


To (un)subscribe to the Vim Development list

mail vim-dev-(un)subscribe@babayaga.math.fu-berlin.de


Each mailing list serves a different purpose and you should not crosspost
between them. This is a brief description of each list:

<vim@babayaga.math.fu-berlin.de >
For discussions about using existing versions of Vim: Useful mappings,
questions, answers, where to get a specific version, etc.
<vim-dev@babayaga.math.fu-berlin.de >
For discussions about changing Vim: New features, porting, etc.
<vim-announce@babayaga.math.fu-berlin.de >
Announcements about new versions of Vim and also beta-test versions and ports
to different systems. No discussions here, please.

If you have a question about the usage of Vim then please post it to comp.
editors or to the vim mailing list . Please note that if you send a message
to a Vim mailing list but are not subscribed, your message will be discarded.
You must subscribe in order to send mail to the mailing lists. Do not send mail
 to the mailing lists for subscription or unsubscription. (The maintainer of
the list hates that! So do the people subscribed to the lists.)

3.3 Is there an archive available for the Vim mailing list?

There is an archive available for the announcements made on the vimannounce
mailing list at http:// www.egroups.com/list/vimannounce/

There is also a mail archive available by FTP if you need to check out old
messages sent to one of the other lists. They are available at:

<URL:ftp://ftp.ii.uib.no/pub/vim/mail-archive/vim/maillist.html >
<URL:ftp://ftp.ii.uib.no/pub/vim/mail-archive/vimdev/ maillist.html >
<URL:ftp://ftp.ii.uib.no/pub/vim/mail-archive/vimannounce/ maillist.html >

3.4 Where can I report bugs?

Well, you don't need to because there are none. ;-) But on the off chance
that you may find an unexpected feature, you may send a description of it to
the Vim Development list. Take a look at <URL:http://www.math.fu-berlin.
de/~guckes/vim/development.html#bugreport > to see what type of information
should be sent when making a bug report. We are looking for someone to take
over the tasks of our previous bug maintainer. If you are interested, send a
message to Bram <mool@oce.nl >. If you have patches that you would like to
submit for approval and incorporation in future versions of Vim, you can send
them to Bram <mool@oce.nl >.

3.5 Where can the FAQ be found?

This FAQ will be posted on a (hopefully) regular basis to the comp.editors
newsgroup. The latest version can be found on http://www.vim.org/faq/
Eventually, it should make its way into news.answers and rtfm.mit.edu . You can
 also find a searchable version of this and many more FAQs at the Hypertext FAQ
 Archive at <URL:http://www.landfield.com/faqs/ >.


3.6 What if I don't find an answer in this FAQ?

This FAQ covers mainly Vim-specific questions. You may find more information
suitable for most Vi clones by reading the Vi FAQ. It is posted regularly on
comp.editors . You can also find a copy at <URL:ftp://rtfm.mit.
edu/pub/usenet-by-group/comp.editors >. Please note that although I maintain
the FAQ, I am not the best resource to answer questions about Vim. If you
send a question about using Vim diretly to me, 9 times out of 10 I will
redirect you to the Vim mailing list or to comp.editors . So you might as
well send your questions directly there since you're liable to get a more
accurate and useful response than I could give you.

4 AVAILABILITY


4.1 What is the latest version of Vim?

The latest version is 4.6. The latest alpha release is 5.0l (as of August 6
1997). You should not use the alpha version unless you can read and modify C
code rather well. Otherwise, I suggest you wait for the beta release.

4.2 Where can I find the latest version of Vim?

The main archive for the latest versions of Vim is <URL:ftp://ftp.oce.
nl/pub/misc/vim >. The directory structure:

        /pub/misc/vim/amiga
        /pub/misc/vim/atari
        /pub/misc/vim/beta-test
        /pub/misc/vim/os2
        /pub/misc/vim/pc
        /pub/misc/vim/unix


The latest public release can be found in the atari, amiga, os2, pc, and unix
directories. The latest beta-test versions can be found in the beta-test
subdirectories.

You can probably also find the latest version at:

<URL:ftp://jagubox.gsfc.nasa.gov/pub/unix/vim/ > (USA, fast)
<URL:ftp://ftp.nuxi.com/pub/vim > (USA, fast)
<URL:ftp://nuxi.ucdavis.edu/pub/vim > (USA, fast)
<URL:ftp://petrified.cic.net/mirrors/vim/ > (USA)
<URL:ftp://ftp.fu-berlin.de/pub/misc/editors/vim/ > (Germany)
<URL:ftp://ftp.is.co.za/applications/editors/vim/ > (South Africa)
<URL:ftp://ftp.progsoc.uts.edu.au/pub/vim/ > (Australia)
<URL:ftp://ftp.uni-erlangen.de/pub/utilities/vim/ > (Germany, incomplete)

4.3 What platform does it run on?

Vim should compile with no problems on most flavors of Unix and on DOS, OS/2,
Ataris, Amigas, Windows 95, and NT. Binaries for other systems are also
available.

Linux-Motif (statically linked)
<URL:ftp://ftp.blarg.net/pub/vim >
<URL:ftp://ftp.nuxi.com/pub/vim/linux >
Mac
Some work has just begun for the Mac port. It is not yet available.
OS/2
A binary is available in <URL:ftp://ftp.oce.nl/pub/misc/vim/os2 >.
Win32 (for Windows 95 and NT on Intel, Alpha, MIPS and PowerPC)
<URL:ftp://www.halcyon.com/local/gvr/vim/ >.
VMS
Some preliminary patches have been sent on the development list. Eventually,
they will be available as a separate set of files.


4.4 What do I need to compile and install Vim?

Unless you are on a Unix station, you may not need to compile Vim since there
are various binaries available for Windows, Windows 95, Windows NT, DOS, OS/2
and Amiga. But if you need to compile it, you must have a C compiler and a make
 utility. Most commercial C compilers come bundled with a make utility, so if
you've got one of those, you're in luck. If you need a compiler or if your make
 utility doesn't like the Makefiles provided with Vim, you can get the GNU C
compiler and GNU make at <URL:ftp://prep.ai.mit/edu/pub/gnu > and its mirrors.
 At that same site, you can also find sed, binutils, and other GNU tools
(such as gzip) which can be useful on certain systems. For DOS systems, you can
 look in <URL:ftp://ftp.coast.net/SimTel/msdos/ >. If you plan on compiling the
 GUI version of Vim under Unix, you must have some kind of widget library.
One of these three should suffice:

Motif libraries
These libraries are commercial but are distributed with a number of operating
systems. You can find out how to purchase it by going to <URL:http://www.rdg.
opengroup.org/ >.
Athena libraries
This is a freely available widget set which is included in the X11
distribution. This is a no frills library which implements a number of
widgets that are necessary when building a GUI. Various other similar libraries
 have been built from the Athena widget set. These variations allow a 3D look
and a NextStep look. These variations are not part of the X11 distribution. The
 X11 distribution is available at <URL:ftp://ftp.x.org/ >.
Lesstif
This is a free Motif clone. It is available at <URL:http://www.lesstif.org/ >.


5 TIPS AND TECHNIQUES

Note: This section contains various macros written in Vim's macro language,
called ``<> notation'' (you can find the description by doing ``:h
key_notation''). All macros should be entered as is in your .vimrc file or on
Vim's command line. You should even be able to cut and paste the information.
This is a short description of the language:

Any printable characters are typed directly, except backslash and '<'.
A backslash is represented with ``\\'', double backslash.
A real '<' is represented with ``\<''.
``<key>'' means the special key typed. A few examples:

   <Esc>Escape key
   <C-G>CTRL-G
   <Up>cursor up key
   <C-LeftMouse>Control- left mouse click
   <S-F11>Shifted function key 11
   <M-a>Meta- a  ('a' with bit 8 set)
   <M-A>Meta- A  ('A' with bit 8 set)
   <t_kd>"kd" termcap entry (cursor down key)


If you want to use this notation in Vim, you have to remove the 'B' flag from
'cpoptions' and make sure the '<' flag is excluded. The default values for
cpoptions should work fine.

:set cpo=ceFs


For mapping, abbreviation and menu commands you can then copy-paste the
examples and use them directly. Or type them literally, including the '<' and
'>' characters. This does NOT work for other commands, like ``:set'' and ``:
autocmd''!

Other tips, not appearing in this FAQ, can be found by doing ``:h tips''.

5.1 How do I use the help files?

Help can be found for all functions of Vim. In order to use it, use ``:h''.
This will bring you to the main help page. On that first page, you will find
explanations on how to move around. Basically, you move around in the help
pages the same way you would in a read-only document. You can jump to
specific subjects by using tags. This can be done in two ways:

Use the ``<Ctrl-]>'' command while standing on the name of a command or option.
 This only works when the tag is a keyword. ``<Ctrl-LeftMouse>'' and
``g<LeftMouse>'' work just like ``<Ctrl-]>''.
use the ``:ta subject'' command. This works with all characters.

Use ``<Ctrl-T>'' to jump back to previous positions in the help files. Use ``:
q'' to close the help window.

If you want to jump to a specific subject on the help pages, use ``:h
{subject}''. If you don't know what to look for, try ``:h index'' to get a list
 of all available subjects. Use the standard search keys to locate the
information you want. By version 6 or 7, we should have a search engine
available. ;-)


5.2 Why is a backup file written even if I set nobackup?

In order to keep Vim from writing a backup, you must also do ``:set
nowritebackup''.


5.3 How can I keep Vim from beeping all the time?

Well, you can use ``set noerrorbells" but it does not turn off the bell for all
 cases. It only makes a difference for error messages; the bell will be
always be used for a lot of errors without a message (e.g., hitting <Esc> in
Normal mode).

If you want Vim to stop beeping then all you need is ``:set vb'' which tries to
 do a screen flash rather than an audible beep. Some terminals can't do
screen flashes, but if yours does and you don't want it to flash or beep then
use ``:set vb t_vb=''.

5.4 How do I map the Tab key?

:map <Tab> right-hand-side

5.5 How do I map the Esc key?

On some keyboards the escape key is not placed very well. It's either part of
the numeric block or it can be a small button (as with some Macintosh
keyboards). But do not despair - make your own escape key! You can map one of
the commands keys you do not need to Esc. Example: map CTRL-O to ESC:

:map <C-O> <Esc>

5.6 How do I tell Vim where the helpfile is?

To tell Vim where to find the help file, ``:set helpfile'' to the correct
value, i.e., including the full path. As with most options you can abbreviate
``helpfile'' to ``hf''. On the other hand, if your VIM environment variable
points to the directory containing the help file, vim will find the help file
with no need to ``:set hf=''.


5.7 How do I get back to the exact position within a line I have marked with
'a'?

Use ```a'' (that's a backtick!). If the backtick is awkwardly placed on your
keyboard, the following maping may be useful to you:

map ' `


5.8 How do I read in the output of a command?

Use ``:r!command''.

5.9 Why can't I abbreviate ``'xy''?

The abbreviation consists of a non-id character followed by two id characters,
 which does not satisfy either category of a ``full-id''. However, ``_ps''
and ``'p'' will work.


5.10 How do I jump to the beginning/end of the highlighted text?

The command 'o' will jump to the beginning/end of the highlighted text.


5.11 Why does completion of ``:set n'' not show negated settings, e.g.,
``noautoindent''? Completion of ``:set no'' seems to work.

The thing is that the ``no'' is not actually part of the option's name; the
name comes after that. So after ``no'', Vim knows to complete any boolean
setting name (starts the completion just after the ``no'', which is not part of
 the name). After ``n'', Vim will complete all setting names starting with
``n''. It would be a bummer if you wanted to complete ``number'', but had to
wade through all the boolean option names with ``no'' prepended too.

5.12 Is there a command to remove any or all digraphs?

No. The digraphs table is defined at compile time. You can only add new ones.
Adding a command to remove digraphs is on the todo list.

5.13 How do I use a spell checker with Vim?

You can call a non-interactive spell checker from Vim without a problem. A
function to look up a word is included with the command ``K''. So what you do
is get such a spell checker, then you issue the command ``:set
keywordprg=ispell'', and then hit ``K'' on the word you want to look up, i.e.,
 check. If you need to give options to your spell checker command, escape all
spaces with a backslash.

If you need to use an interactive spell checker and are working with Unix,
you can try this approach proposed by Ives Aerts <ives@sonycom.com >:

noremap ;ispell :%! ispell-filter<CR><C-L>


where ispell-filter is the following script:

#!/bin/sh
#
# This little script can be used to run ispell on stdin, returning the result
# through stdout.
# It can be used from VI like this (or map it to a key sequence):
# :%! ~/bin/ispell-filter
#
cat > /tmp/tmp.$$
ispell $* /tmp/tmp.$$ < /dev/tty > /dev/tty
cat /tmp/tmp.$$
rm -f /tmp/tmp.$$


or this macro proposed by Dr. Charles E. Campbell Jr. <cec@gryphon.gsfc.nasa.
gov >:

map #fi :w<CR>:!ispell %<CR>:e %<CR>



5.14 Can I copy the character above the cursor to the current cursor
position?

In Insert mode, you can copy the character above the cursor to the current
cursor position by typing <Ctrl-Y>. The same can be done with the characters
below the cursor by using <Ctrl-E>. This is neat when you need to duplicate
partial lines without going through the process of yanking a line and
deleting the unwanted part.

5.15 How do I remove empty lines?

To remove all empty lines do ``:g/^$/d''. ":g/^\s\+$/d" deletes blank lines, ie
 lines that contains spaces and tabs only.


5.16 How do I reduce a range of empty lines into one line only?

You can try ``:v/./.,/./-1join''. Note that this will give an error message
if the empty lines are at the end of the file. To correct this, use the
following mapping instead:

map  _b  GoZ<Esc>:g/^[ <Tab>]*$/,/[^ <Tab>]/-j<CR>Gdd



5.17 How can I paste large amounts of text between two running sessions of
Vim?

If you are using the GUI version of Vim, with the Motif or Athena interface,
you can actually cut and paste between the two, and text will be copied
exactly; that is, tabs will not change into spaces, and if you copy a
rectangular block, then that is what you will paste too!

Otherwise, in a terminal Vim, use these mappings:

" _Y: Yank the highlighted block of text (or a single line) to a tmp file.
" _P: Put the text yanked with \_Y (possibly in another invocation of Vim).
"
nmap_Y:.w! ~/.vi_tmp<CR>
vmap_Y:w! ~/.vi_tmp<CR>
nmap_P:r ~/.vi_tmp<CR>


Now you just highlight the area you want to copy with ``V'' etc, and yank it
with ``_Y''. Then you can paste it in another Vim with ``_P''.

5.18 Can I use compressed versions of the help files?

For those that are really short on disk space, you can compress the help
files and still be able to view them with Vim. This example assumes you have
gzip on your system. You do have it, don't you? :-) If not, you will need to
adapt it to work with a different compression utility.

1.
Compress all the help files: ``gzip doc/*.txt''.
2.
Edit doc/vim_tags and do :%s=\\.txt<Tab>/=.txt.gz<Tab>/=
3.
Add these lines to your .vimrc:

set helpfile=<dirname>/vim_help.txt.gz
autocmd BufReadPost *.txt.gz set bin | '[,']!gunzip
autocmd BufReadPost *.txt.gz set nobin
set cmdheight=2


Where ``dirname'' is the directory where the help files are. If you already
have included autocommands to edit ``.gz'' files you should omit the two
``autocmd'' lines.

5.19 How come I can't set option ``xxxx''?

Some options are compiled into Vim. If you want to enable these options, then
you must modify the feature.h file. You can see what compile-time options are
available by looking at the version number (:ver). It will give you something
like this:

Compiled with (+) or without (-):
+autocmd +builtin_terms +cindent -compatible +digraphs - emacs_tags +fork()
-GUI +insert_expand -langmap +lispindent -rightleft +smartindent -terminfo
+viminfo +writebackup +X11

As the example shows, all options compiled into the Vim binary are preceded
by a '+'. All options that are not compiled in are preceded by a '-'. All
options that do not appear in this list do not need to be compiled in.

5.20 How do I format a block of C code?

To format C code, use = instead of Q. Try ``:h C_indenting'' to get more
information on controlling the way your code is formatted.


5.21 How do I put a command onto the command history without executing it?

You need only end the input with <ESC> (not <Ctrl-V><Esc>).


5.22 Why do I hear a beep (why does my window flash) about 1 second after I hit
 the Escape key?

This is normal behavior. If your window flashes, then you've got the visual
bell on. Otherwise, you should hear a beep.

Vim (and most, if not all, other implementations of Vi) needs a timeout to tell
 the difference between a simple escape and, say, a cursor key sequence. When
you press a key in normal mode (and even in insert mode) and that key is the
beginning of a mapping, Vim waits a certain amount of time to see if the rest
of the mapping sequence follows. If the mapping sequence is completed before
a given timeout period, the mapping for that sequence of keys is applied. If
you interrupt the mapping, the normal actions associated with the keys are
executed.

For example, if you have a mapping defined as ``:imap vvv Vim is great!!''
and you type ``vvv'' quickly, the ``Vim is great!!'' will be inserted into your
 text. But if you type ``vv v'' then that is what will put into your text. This
 is also true if you type ``vvv'' too slowly where ``too slowly'' is longer
than the value for the timeout option. Setting the timeout option to a larger
value can help alleviate problems that appear when using function keys over a
slow line. Do ``:h timeout'' for more information on using this option and
its cohorts.


5.23 How do I make the 'c' and 's' commands display a '$' instead of deleting
the characters I'm changing?

Add ``:set cpoptions=ces$'' to your .vimrc. Vi-compatible behavior can be
controlled like this. Do ``:help cpoptions'' for more information.


5.24 How do I add a line before each line with ``pattern'' in it?

1.
Yank the line using Y
2.
Insert the line with ``:g/pattern/put!''


5.25 How can I delete the newline which is followed by a given character,
such as ``|''?

Look at this problem this way: If there is a newline before the character
then the character is the first character of the next line, i.e., it follows
the start-of-line meta character (^). So the command to use is to look globally
 for all lines starting with the given character and the command to use on
these lines is ``go back one line'' and ``join'' which will remove the next
newline. The resulting command is:

:g/^|/-1join



5.26 How do I use the join command within a range of lines that ends with ``*''
 and begins with the previous ``|''?

:?^|?,/*$/join



5.27 How do I map/unmap an abbreviation or a map!ed key sequence?

In either case, ``:set paste'' will do the trick. Use ``:set nopaste'' to
return to normal.

For map!ed key sequences, you have a these tricks also;

After typing the first key of the key sequence, pause about 1 second before
typing the rest of the sequence.
Type <Ctrl-V> before typing the first key in the key sequence.

Normally, you shouldn't need these tricks. When ``:unmap'' finds an argument
that is not a ``from'' part, it looks for a matching ``to'' part and unmaps
that one.


5.28 When I use my arrow keys, Vim changes modes, inserts weird characters in
my document but doesn't move the cursor properly. What's going on?

There are a couple of things that could be going on: either you are using Vim
over a slow connection or Vim doesn't understand the key sequence that your
keyboard is generating.

If you are working over a slow connection (such as a 2400 bps modem), you can
try to set timeout or ttimeout. These options, combined with timeoutlen and
ttimeoutlen, may fix the problem. Do ``:h timeout'' and ``:h timeoutlen'' for a
 better description on how to use them.

The preceding procedure will not work correctly if your terminal sends key
codes that Vim does not understand. In this situation, your best option is to
map your key sequence to a matching cursor movement command and save these
mappings in a file. You can then ``:source'' the file whenever you work from
that terminal.


5.29 How do I ``auto-outdent'' some lines containing certain keywords (i.e.have
 auto-indenting but towards the left margin instead of the right margin)?

For example (make sure you adapt the example to your personal needs):

for k=1:10,
  stuff
  ..
  end;
  ^^^ This word marks the end of a loop and I'd like it to be
      automatically outdented to the same column as the word
      for.


The following macro will do this (from Raul Segura Acevedo <raul@hplara.
iquimica.unam.mx >):

:iab  end; <C-D>end;


This abbreviation takes effect when you type a non-keyword character after it
(``;'', ``!'', space, tab, <Esc>, <CR>, etc). You can load this macro
automatically using the following autocommands:

au!  BufEnter   *.f,*.ff        iab     end;<C-D>end;
au!  BufLeave   *.f,*.ff        iunab   end;


5.30 Is there a repository for Vim macros?

As a matter of fact, there is. You can find the latest versions of
contributed macros at <URL:http:// www.grafnetix.com/~laurent/vim/macros.html
>. At the time this version of the FAQ was updated, the following macros were
available:

A file browser
Some macros to edit HTML code
Macros to deal with numbered lists
A Tic Tac Toe game


5.31 If I have a mapping/abbreviation whose ending is the beginning of
another mapping/abbreviation, how do I keep the first from expanding into the
second one?

Instead of using :map lhs rhs, use :noremap lhs rhs. For abbreviations, use
noreabbrev lhs rhs. The ``nore'' prefix prevents the mapping or abbreviation
from being expanded again. You must be using version 4.5 or greater.


5.32 Modelines are cool but Vim's modeline support is too restrictive. How
can I improve it?

From Benjamin Elijah Griffin <eli@NetUSA.Net >:

Vim modelines are crippled to reduce the security hazards of modelines. For
much closer to vi modeline behavior (with the major risks involved) you can use
 Benjamin Elijah Griffin's modeline autocmd system. You can find it at <URL:
http://www.netusa.net/~eli/ src/modeline.html >.


5.33 How can I use different .vimrc settings for different types of files?

There are a few ways to do this. All of them involve the use of autocommands.
Try ``:h  autocommand'' for more information.

You can define autocommands which do everything for you in your .vimrc file:

    au!BufRead   *.c,*.cc,*.h    set fo=croq cin noic
    au!BufEnter  *.c,*.cc,*.h    ab #i #include
    au BufEnter  *.c,*.cc,*.h    ab #d #define
    au BufEnter  *.c,*.cc,*.h    map _hello_world :"Hello World"<CR>
    au BufEnter  *.c,*.cc,*.h    normal _hello_world
    au!BufLeave  *.c,*.cc,*.h    unab #i  | unab #d
    au BufLeave  *.c,*.cc,*.h    unmap _hello_world


The ``!'' is used just in the first autocommand for each event (BufEnter,
BufLeave, etc.).

Or you can define one autocommand for each file type which loads a specific .
vimrc file containing the settings you require.

autocmd BufNewFile *.tex read ~/.vim/texmodel
autocmd BufEnter *.tex source ~/.vim/texrc
autocmd BufLeave *.tex source ~/.vim/notexrc


Remember that all settings that you modify in a BufEnter or BufNewFile event
may need to be unset with a corresponding BufLeave event. By using a first file
 pattern with a value of ``*'', you can define default settings for all your
files. The ``mapclear'' and ``abclear'' commands can clear all your mappings or
 abbreviations if needed.


5.34 How can I search for tags when running Vim over a telnet session?

Darren Hiebert <darren@sirsi.com > says:

Ctrl-] is the the default telnet escape key. Most version of telnet allow
changing or disabling the default escape key. See the man page. If possible,
try to use ``rsh'' instead of ``telnet''. It will avoid this problem.

6 DOS-, WINDOWS-, WIN32-SPECIFIC QUESTIONS


6.1 Why does the Win32 version of Vim update the screen so slowly on Windows
95?

The support for Win32 console mode applications is very buggy in Win95. For
some unknown reason, the screen updates very slowly when Vim is run at one of
the standard resolutions (80x25, 80x43, or 80x50) and the 16-bit DOS version
updates the screen much more quickly than the Win32 version. However, if the
screen is set to some other resolution, such as by ``:set columns=100'' or ``:
set lines=40'', screen updating becomes about as fast as it is with the
16-bit version.

Changing the screen resolution makes updates faster, but it brings problems
with it of its own. External commands (e.g., ``:!dir'') can cause Vim to freeze
 when the screen is set to a non-standard resolution, particularly when columns
 is not equal to 80. It is not possible for Vim to reliably set the screen
resolution back to the value it had upon startup before running external
commands, so if you change the number of lines or columns, be very, very
careful. In fact, Vim will not allow you to execute external commands when
columns is not equal to 80, because it is so likely to freeze up afterwards.
The maintainer of the Win32 port, George V. Reilly, says he's almost done
with the GUI version of Vim. When it is completed, it should fix all these
problems. In his own words:

My position at this point is that the console mode APIs are irredeemably broken
 on Windows 95 and that I'm no longer interested in trying to come up with
workarounds and hacks when my limited time is better spent trying to get an
alpha of the Windows GUI version out the door. I strongly urge you to use one
of the three standard resolutions (80x25, 80x43, or 80x50) and wait for the GUI
 version. Or upgrade to NT, where the console mode stuff works. Sorry.

None of the above applies on Windows NT. Screen updates are fast, no matter how
 many lines or columns the window is set to, and external commands will not
cause Vim to freeze.


6.2 So if the Win32 version updates the screen so slowly on Windows 95 and
the 16-bit DOS version updates the screen quickly, why would I want to run
the Win32 version?

Firstly, the Win32 version isn't that slow, especially when the screen is set
to some non-standard number of lines or columns. Secondly, the 16-bit DOS
version has some severe limitations: it can't edit big files and it doesn't
know about long filenames. The Win32 version doesn't have these limitations and
 it's faster overall (the same is true for the 32-bit DJGPP DOS version of
Vim). The Win32 version is smarter about handling the screen, the mouse, and
the keyboard than the DJGPP version is.


6.3 And what about the 16-bit DOS version versus the Win32 version on NT?

There are no good reasons to run the 16-bit DOS version on NT. The Win32
version updates the screen just as fast as the 16-bit version when running on
NT. All of the above disadvantages apply. Finally, 16- bit DOS applications can
 take a long time to start up and will run more slowly. On non-Intel NT
platforms, the DOS version is almost unusably slow, because it runs on top of
an 80x86 emulator.

6.4 Why can't I paste into Vim when running Windows 95?

In the properties dialog box for the MS-DOS window, go to ``MS-DOS
Prompt/Misc/Fast pasting'' and make sure that it is not checked. You should
also do ``:set paste'' in VIM to avoid unexpected effects. See ``:h paste''.

Also, in the Properties dialog's ``Misc'' tab, you want to make sure that
``Mouse Exclusive Mode'' is not checked. If you want to use the mouse in the
Vim way, also make sure ``Mouse Quick Edit'' is not checked. (You can still cut
 and paste with the mouse by using the toolbar buttons.)

6.5 How do I type dead keys on Windows 95?

(A dead key is an accent key, such as acute, grave, or umlaut, that doesn't
produce a character by itself, but when followed by another key, produces an
accented character, such as a-acute (á), e-grave (è), u- umlaut (ü), n-tilde
 (?), and so on. Very useful for most European languages. English-language
keyboard layouts don't use dead keys, as far as we know.)

You don't. The console mode input routines simply do not work correctly in
Windows 95, and we have not been able to work around them. In the words of a
senior developer at Microsoft:

Win95 console support has always been and will always be flaky.

The flakiness is unavoidable because we are stuck between the world of MS-DOS
keyboard TSRs like KEYB (which wants to cook the data; important for
international) and the world of Win32.

So keys that don't "exist" in MS-DOS land (like dead keys) have a very
tenuous existence in Win32 console land. Keys that act differently between
MS-DOS land and Win32 console land (like capslock) will act flaky.

Don't even mention the problems with multiple language keyboard layouts...

You may be able to fashion some sort of workaround with the digraphs
mechanism.

Alternatively, you can try one of the DOS versions, where deadkeys do work.

6.6 How do I type dead keys on Windows NT?

Dead keys work on NT. Just type them as you would in any other application.


6.7 When will a real GUI version of Vim (gvim) for Win32 with scrollbars,
menus, pasting from the clipboard, and so on become available?

Work has begun on a GUI version of Vim for Win32. Apart from the features you
might expect in gvim, it is expected that this version will also be able to
handle dead keys correctly and that the problems with external commands will be
 a thing of the past.


6.8 On a Win32 machine, I'm using Vim to edit a symbolically linked file on a
Unix NFS file server. When I write the file, Vim does not "write through" the
symlink. Instead, it deletes the symbolic link and creates a new file in its
place. Why?

On Unix, Vim is prepared for links (symbolic or hard). A backup copy of the
original file is made and then the original file is overwritten. This assures
that all properties of the file remain the same. On non- Unix systems, the
original file is renamed and a new file is written. Only the protection bits
are set like the original file. However, this doesn't work properly when
working on an NFS-mounted file system where links and other things exist. The
only way to fix this in the current version is not making a backup file, by
``:set nobackup nowritebackup''.


6.9 How do I copy text from Windows applications to the DOS version of Vim?

From John Velman, <velman@igate1.hac.com >:

1.
To get Vim to run in a window, instead of full screen, press <Alt+Enter>.
This toggles back and forth between full screen and a DOS window.
2.
Issue the command ``:set paste''.
3.
To paste something *into* Vim, put Vim in insert mode.
4.
Put the text you want to paste on the windows clipboard.
5.
Click the control box in the upper left of the Vim window. (This looks like a
big minus sign). If you don't want to use the mouse, you can get this with
<Alt+Spacebar>.
6.
On the resulting dropdown menu choose 'Edit'.
7.
On the child dropdown menu choose 'Paste'
8.
Issue the command ``:set nopaste''.

To copy something from the Vim window to the clipboard,

1.
Select the control box to get the control drop down menu.
2.
Select 'Edit'.
3.
Select 'Mark'.
4.
Using either the the keys or the mouse, select the part of the Vim window
that you want to copy. To use the keys, use the arrow keys, and hold down shift
 to extend the selection.
5.
When you've completed your selection, press ``<Enter>.'' The selection is now
in the Windows clipboard. By the way, this can be any rectangular selection,
for example columns 4-25 in rows 7-10. It can include anything in the Vim
window: the output of a ``:!dir'', for example.

From Stan Brown <stbrown@nacs.net >: In Windows 95, you can use a simpler
procedure, which works even when you're using the mouse in the Vim way inside
the Vim window (see question 6.4). To paste into Vim, put Vim in insert mode
and click the Paste button on the Vim window's toolbar. (Depending on your
setup, you may want to use ``:set paste'' before and ``:set nopaste'' after
pasting.)

To copy from Vim to the clipboard, click the Mark button (the square) on the
toolbar, highlight the desired text with the mouse, and click the Copy button.



6.10 Why does my Caps Lock affect all the keys characters for all the keys
instead of just the letters?

It's actually caused by Windows 95. When CapsLock is down, it acts just as if
Shift were being held down: everything gets shifted, not just the
alphabetical keys.

6.11 How do I change Vim's window size in Windows?

If ``:set lines=##'' doesn't work for you, then you should use the ``:mode''
command. Look up ``:h :mode'' for more info.

7 UNIX-SPECIFIC QUESTIONS


7.1 How do I turn off the message ``Thanks for flying Vim'' on Unix stations?

When using Vim in an xterm it renames the title of that window to ``Thanks
for flying Vim'' on exit. Use ``:set notitle'' to stop this behavior.


7.2 How do I prevent <Ctrl-Z> from suspending Vim?

Map <Ctrl-Z> to prevent the suspending. Here are some suggestions:

1.
Make <Ctrl-Z> do nothing:

map <C-Z> <C-V><C-V>


2.
Make <Ctrl-Z> start a shell:

:map <C-Z> :shell<CR>


3.
Make <Ctrl-Z> give an error message:

:map <C-Z> :"suspending disabled<CR>


For the last example, the double quote is necessary in order to keep the
message on the status line.

7.3 How can I make Vim faster on a Unix station?

The GUI support in Vim 4.0 can slow down the startup time noticeably. Until Vim
 supports dynamic loading, you can speed up the startup time by compiling two
different versions of Vim: one with the GUI and one without the GUI and install
 both. Make sure you remove the link from $bindir/gvim to $bindir/vim when
installing the GUI version, though.

If screen updating is your problem, you can run Vim in screen. screen is an
ascii terminal multiplexer. The latest version can be found at <URL:ftp://ftp.
uni-erlangen.de:/pub/utilities/screen >.

7.4 In Unix, how do I make Vim more colorful?

You can change some termcap values to send to the screen the proper codes to
change some colors (providing your terminal supports color). Here are some
examples of how to do this if you do ``:h unix'' but it seems as though they
don't work all that well. But they help to understand what has to be done:

:set t_me=<Esc>[0;1;36m     " normal mode (undoes t_mr and t_md)
:set t_mr=<Esc>[0;1;33;44m  " reverse (invert) mode
:set t_md=<Esc>[1;33;41m    " bold mode
:set t_se=<Esc>[1;36;40m    " standout end
:set t_so=<Esc>[1;32;45m    " standout mode
:set t_ue=<Esc>[0;1;36m     " underline end
:set t_us=<Esc>[1;32m       " underline mode start


Quoting Tony Nugent:

You can do some interesting things by putting ansi colour sequences into
those capabilities. What's given here are just examples, and some
combinations don't work very well. You need to discover for yourself a
configuration that works. For example, end-modes need to switch everything back
 to normal as well as turn things off.

Just load ~/.vimrc, play around with the values, save it and then see what it
looks like by sourcing it (:so ~/.vimrc).

Don't forget to do things like ``:/<Ctrl-D>'' and ``:map'' to see all the
different effects. And don't forget about the ``:set highlight='' string to
fine-tune how the different capabilities are used.

BTW, something like this also works for DOS and Win32 Vims! So it should also
work well with windows or any ansi- and vt100- compatible terminal mode capable
 of displaying colours (which includes all colour pc's). It doesn't work so
well in plain old xterm's (YMMV - your milage may vary).

You can find a list of terminal codes here:

<URL:http://www.cs.utk.edu/~shuford/terminal_index.html >
<URL:ftp://cs.utk.edu/pub/shuford/terminal/ >
<URL:ftp://gatekeeper.dec.com/pub/DEC/termcaps >


New Stuff

Q: Why can't I map CTRL-C? A: :help map_CTRL_C

It's not possible to use a CTRL-C in the {lhs}.  You just can't map CTRL-C.
The reason is that CTRL-C must always be available to break a running command.



Allowing to map CTRL-C is very dangerous because it might then be impossible to
 get out of Vim. (Btw, disallowing to map CTRL-C is Vi compatible.) Btw, you
*can* map 'Esc' in Insert mode - but then you will need to use CTRL-C to get
back to normal-mode.

Q: How can I start vim without reading any setup files?
A: "vim -u NONE"


Q: Can Vim be run on Windows98?
A: Yes.  Known users:
   Mike Bunker Mike_Bunker@nfuel.com

Q: Can Vim be run on Windows2000?
A: ???


WindowsNT
Q: Why does ":w file" overwrite 'file' even though it it "read-only"?
A:  ???




Links

Some pages that you should know about:

Vi Pages
http://www.math.fu-berlin.de/~guckes/vi/
Vi related pages. List of available Vi clones and Vi documents available
online.
Vim Pages
http://www.vim.org/
Everything else about Vim not mentioned in this FAQ.


This webpage and FAQ is maintained by

Sven Guckes guckes@vim.org


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店