allanswers.org - Vim Editor FAQ

 Home >  Softwareeditor-faq >

Vim Editor FAQ

Section 1 of 2 - Prev - Next


Archive-name: editor-faq/vim
Posting-Frequency: monthly (second Monday)
Last-modified: Mon Feb  9 21:27:50 EST 1998
URL: http://www.grafnetix.com/~laurent/vim/faq.html

                             The Vim Editor FAQ

Created: Tue Mar 12 00:00:00 EST 1996
Last Updated: Date: 1998/02/08 18:03:21
Version: Revision: 1.25
Author: Laurent DUPERVAL 
This Page: 
Vim Pages: 

This article contains answers to Frequently Asked Questions about the Vim
editor. Questions marked by  [CHANGED] are questions that have been modified
since the last release of the FAQ. Questions marked by  [NEW] are new
questions. The following topics are addressed:

Contents

   * Contents
   * 1 ABOUT THIS FAQ
        o 1.1 What versions of Vim does this FAQ cover?
        o 1.2 Who maintains this FAQ?
        o 1.3 Why him?
        o 1.4 Can I add to it?
        o 1.5 What are the restrictions on this FAQ?
        o 1.6  [CHANGED] Acknowledgements
   * 2 GENERAL INFORMATION
        o 2.1 What is Vim?
        o 2.2 Who wrote Vim?
        o 2.3 Is Vim compatible with Vi?
        o 2.4 What are some of the improvements of Vim over Vi?
        o 2.5 What are the improvements of Vim 4 over Vim 3.x?
        o 2.6 What are the improvements of Vim 5.x over Vim 4.x?
        o 2.7 Is Vim free?
   * 3 RESOURCES
        o 3.1  [CHANGED] Where can I learn more about Vim?
        o 3.2 Is there a mailing list available?
        o 3.3 Is there an archive available for the Vim mailing list?
        o 3.4  [CHANGED] Where can I report bugs?
        o 3.5 Where can the FAQ be found?
        o 3.6 What if I don't find an answer in this FAQ?
   * 4 AVAILABILITY
        o 4.1  [CHANGED] What is the latest version of Vim?
        o 4.2 Where can I find the latest version of Vim?
        o 4.3  [CHANGED] What platform does it run on?
        o 4.4  [CHANGED] What do I need to compile and install Vim?
   * 5 TIPS AND TECHNIQUES
        o 5.1 How do I use the help files?
        o 5.2 Why is a backup file written even if I set nobackup?
        o 5.3 How can I keep Vim from beeping all the time?
        o 5.4 How do I map the Tab key?
        o 5.5 How do I map the Esc key?
        o 5.6 How do I tell Vim where the helpfile is?
        o 5.7 How do I get back to the exact position within a line I have
          marked with 'a'?
        o 5.8 How do I read in the output of a command?
        o 5.9 Why can't I abbreviate ``'xy''?
        o 5.10 How do I jump to the beginning/end of the highlighted text?
        o 5.11 Why does completion of ``:set n'' not show negated settings,
          e.g., ``noautoindent''? Completion of ``:set no'' seems to work.
        o 5.12 Is there a command to remove any or all digraphs?
        o 5.13 How do I use a spell checker with Vim?
        o 5.14 Can I copy the character above the cursor to the current
          cursor position?
        o 5.15 How do I remove empty lines?
        o 5.16 How do I reduce a range of empty lines into one line only?
        o 5.17 How can I paste large amounts of text between two running
          sessions of Vim?
        o 5.18 Can I use compressed versions of the help files?
        o 5.19 How come I can't set option ``xxxx''?
        o 5.20 How do I format a block of C code?
        o 5.21 How do I put a command onto the command history without
          executing it?
        o 5.22 Why do I hear a beep (why does my window flash) about 1
          second after I hit the Escape key?
        o 5.23 How do I make the 'c' and 's' commands display a '$' instead
          of deleting the characters I'm changing?
        o 5.24 How do I add a line before each line with ``pattern'' in it?
        o 5.25 How can I delete the newline which is followed by a given
          character, such as ``|''?
        o 5.26 How do I use the join command within a range of lines that
          ends with ``*'' and begins with the previous ``|''?
        o 5.27 How do I map/unmap an abbreviation or a map!ed key sequence?
        o 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?
        o 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)?
        o 5.30 Is there a repository for Vim macros?
        o 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?
        o 5.32 Modelines are cool but Vim's modeline support is too
          restrictive. How can I improve it?
        o 5.33 How can I use different .vimrc settings for different types
          of files?
        o 5.34 How can I search for tags when running Vim over a telnet
          session?
        o 5.35  [NEW] I get errors when trying to put scripts in my
          mappings. Why?
        o 5.36  [NEW] When I try to remove mappings in my autocommands, Vim
          says my mappings don't exists. What's going on?
   * 6 DOS-, WINDOWS-, WIN32-SPECIFIC QUESTIONS
        o 6.1 Why does the Win32 version of Vim update the screen so slowly
          on Windows 95?
        o 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?
        o 6.3 And what about the 16-bit DOS version versus the Win32 version
          on NT?
        o 6.4 Why can't I paste into Vim when running Windows 95?
        o 6.5 How do I type dead keys on Windows 95?
        o 6.6 How do I type dead keys on Windows NT?
        o 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?
        o 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?
        o 6.9 How do I copy text from Windows applications to the DOS
          version of Vim?
        o 6.10 Why does my Caps Lock affect all the keys characters for all
          the keys instead of just the letters?
        o 6.11 How do I change Vim's window size in Windows?
   * 7 UNIX-SPECIFIC QUESTIONS
        o 7.1 How do I turn off the message ``Thanks for flying Vim'' on
          Unix stations?
        o 7.2 How do I prevent  from suspending Vim?
        o 7.3 How can I make Vim faster on a Unix station?
        o 7.4 In Unix, how do I make Vim more colorful?

1 ABOUT THIS FAQ

1.1 What versions of Vim does this FAQ cover?

At the time of its creation, version 4.0 was almost complete (3.21 was
already available) therefore the FAQ covers mainly vim4-specific issues. But
some answers may apply to Vim 3.0. There are no plans to make the FAQ
``backward compatible''. ;-) In particular, in various parts of the FAQ, you
will see mentions of ``:h subject'' to get help about a specific subject.
Although the help command works in 3.0, you cannot give it an argument.

1.2 Who maintains this FAQ?

The current maintainer of this FAQ is Laurent Duperval. I can be reached at
. Please insert the keyword NOTSPAM in the Subject
line of your message otherwise it may not reach me.

1.3 Why him?

Well, I volunteered. You could have done it too, had you volunteered before
me. ;-) Besides, after getting so much free and useful stuff off the 'Net, I
decided to give something back in the form of this FAQ.

1.4 Can I add to it?

Sure. Just send your questions (and answers!) to .
Comments and constructive criticism are always welcome.

1.5 What are the restrictions on this FAQ?

Disclaimer: 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.


1.6  [CHANGED] Acknowledgements

The following people have contributed (from near or far) to the answers in
this FAQ. Some of them may not even know about it.

Bram Moolenar 
Sven Guckes 
Robert Webb 
George V. Reilly 
Tony Nugent 
Ingolf Markhof 
Stan Brown 
Raul Segura Acevedo 
Benjamin Elijah Griffin 
Dr. Charles Campbell 

2 GENERAL INFORMATION

2.1 What is Vim?

Vim stands for Vi IMproved. It used to be Vi IMitation, but there are so
many improvements that a name change was appropriate. Vim is a text editor
which includes almost all the commands from the Unix program ``Vi'' and a
lot of new ones. It is very useful for editing programs and other 7-bit or
8-bit ASCII text. 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.

Vim is an editor, not a word processor. 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.

An editor is simply for entering text. Any typesetting or laying out of the
document 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.

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 , 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  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! And much, much more!

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  [CHANGED] 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 a Vim home page available at 

More information can be found in

   * Eli's Vim Page 
   * The Vi Lovers Home Page 

There is a reference card which is only valid for version 5. It is available
in Postscript by sending email to . Please
specify a subject as follows:

   * ``send reference card'' for letter version
   * ``send reference card a4'' for a4 version
   * ``send reference card tex'' for the original LaTeX source

Oleg Raisky  has created a reference guide
for Vim and is available at
. There are versions
available for A4 and US Letter paper sizes.

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 .

   * To (un)subscribe to the Vim Help list

     mail vim-(un)subscribe@vim.org

   * To (un)subscribe to the Vim Announcements list

     mail vim-announce-(un)subscribe@vim.org

   * To (un)subscribe to the Vim Development list

     mail vim-dev-(un)subscribe@vim.org

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


     For discussions about using existing versions of Vim: Useful mappings,
     questions, answers, where to get a specific version, etc.

     For discussions about changing Vim: New features, porting, etc.

     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.editorsor 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 .

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:






3.4  [CHANGED] 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 Developmentlist. Take a look at
 to see what type of information
should be sent when making a bug report. There is also a script included
with newer versions of Vim, which can be used to create 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 .

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
.

3.5 Where can the FAQ be found?

This FAQ will be posted on a (hopefully) regular basis to the
comp.editorsnewsgroup. The latest version can be found on
. It will also be
mirrored at . Eventually, it should make its
way into news.answersand rtfm.mit.edu.

You can also find a searchable version of this and many more FAQs at the
Hypertext FAQ Archiveat .

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
.

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 listor 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  [CHANGED] What is the latest version of Vim?

The latest version is 4.6. The latest beta release is 5.0w (as of February
8, 1998).

4.2 Where can I find the latest version of Vim?

The main archive for the latest versions of Vim is
 The directory structure:

        /pub/vim/amiga
        /pub/vim/atari
        /pub/vim/beta-test
        /pub/vim/os2
        /pub/vim/pc
        /pub/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.

For a complete and updated list of current FTP sites, please refer to
.


4.3  [CHANGED] 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, Windows NT, BeOS and VMS. Binaries for
other systems are also available. A complete list of supported platforms and
available binaries can be found at 


4.4  [CHANGED] 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 (please see .
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  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 .

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
     .
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
     .
Lesstif
     This is a free Motif clone. It is available at
     .

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 ``\<''.
   * ``'' means the special key typed. A few examples:

                                Escape key
                                CTRL-G
                                 cursor up key
                        Control- left mouse click
                              Shifted function key 11
                                Meta- a  ('a' with bit 8 set)
                                Meta- A  ('A' with bit 8 set)
                               "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 ``'' command while standing on the name of a command or
     option. This only works when the tag is a keyword. ``''
     and ``g'' work just like ``''.
   * use the ``:ta subject'' command. This works with all characters.

Use ``'' 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  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  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  

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 :

noremap ;ispell :%! ispell-filter

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.
:

map #fi :w:!ispell %:e %


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 . The same can be done with the characters
below the cursor by using . 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/[ ]*$/d'' deletes lines that aren't blank but look it, too.


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:g/^[ ]*$/,/[^ ]/-jGdd


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.

Section 1 of 2 - Prev - Next

Back to category editor-faq - Use Smart Search
Home - Smart Search - About the project - Feedback

© allanswers.org | Terms of use

LiveInternet