On Sun, December 5, 2010 6:49 pm, Yegappan Lakshmanan wrote:
> As this question has become a FAQ, I decided to write a detailed answer.
>
> When you paste text into a GUI Vim using the mouse, Vim is able to
> detect that you are pasting text. So all the indentation related
> settings (like autoindent, smartindent, cindent, etc.) are ignored and
> the text is pasted literally.
>
> When pasting text into a Vim running in a terminal (like xterm) using
> the mouse, Vim may not be able to detect that you are pasting text. This
> depends on several things: the capability of the terminal to pass the
> mouse events to Vim, Vim is compiled to handle mouse events and access
> the clipboard, the DISPLAY variable is set properly, the Vim 'mouse'
> option is set correctly.
>
> If Vim is able to detect that you are pasting text using the mouse, then
> the pasted text will be inserted literally.
>
> If Vim is not able to detect that you are pasting using the mouse, then
> it will see the pasted text as though you literally typed the text.
> After the first line from the pasted text is inserted, when Vim
> encounters the newline character, because of the indentation settings,
> the next line will start indented. The spaces at the beginning of the
> second line in the pasted text will be inserted leading to additional
> indentation. This will be repeated for subsequent lines. So the pasted
> text will be inserted with stair case indentation.
>
> You can fix this problem in a terminal Vim in several ways:
>
> 1. Build Vim with the +mouse and +xterm_clipboard compile-time options.
>    The normal or big or huge build of Vim includes these options.  Set
>    the 'mouse' option to either 'a' or include 'i'.  When pasting text
>    using the mouse, don't press the Shift key. This will work only if
>    Vim can access the X display. For more information, read the
>    following Vim help topics:
>
>        :help +feature-list
>        :help 'mouse'
>        :help <MiddleMouse>
>        :help x11-selection
>        :help xterm-clipboard
>
> 2. Paste the text using the CTRL-R CTRL-O * command.  This will paste
>    the text literally without any automatic indentation. If you want to
>    paste the text and then fix the indentation, then you can use CTRL-R
>    CTRL-P *. These commands will work only if Vim can access the X
>    display. For more information, read the following Vim help topics:
>
>        :help i_CTRL-R_CTRL-O
>        :help i_CTRL-R_CTRL-P
>        :help quotestar
>
> 3. Set the 'paste' option before pasting the text. This option will
>    disable the effect of all the indentation related settings. Make sure
>    to turn off this option using ':set nopaste' after pasting the text.
>    Otherwise the Vim indentation feature will not work.  Do not
>    permanently set the 'paste' option in your .vimrc file. If you are
>    going to repeat these steps often, then you can set the 'pastetoggle'
>    option to a key. When you press the specified key, the 'paste' option
>    option will be toggled. You can press the key once before pasting the
>    text and the press the key once after pasting the text. Note that
>    when the 'paste' option is set, all the mappings and abbreviations
>    are disabled.  For more information, read the following Vim help
>    topics:
>
>        :help 'paste'
>        :help 'pastetoggle'
>
> You can also refer to the following topics in the user manual:
>
>     :help 04.7
>     :help 09.3
>
>
> - Yegappan

Thanks, I'll update the FAQ.

regards,
Christian

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to