how to solve this strange issue?

19 views
Skip to first unread message

bsmile

unread,
Dec 2, 2010, 3:23:49 AM12/2/10
to v...@vim.org

Dear members,

I copy something and paste to another vi editor, but the leading white space
adds up for subsequent lines. For example, what is copied is

aa
bb
cc
dd

when pasted into another vi, what I get is

aa
bb
cc
dd

Any idea to why this happens and how to solve it?

Thanks,

Sincerely,
Jon
--
View this message in context: http://vim.1045645.n5.nabble.com/how-to-solve-this-strange-issue-tp3289031p3289031.html
Sent from the Vim - General mailing list archive at Nabble.com.

Israel Chauca F.

unread,
Dec 2, 2010, 5:38:42 PM12/2/10
to vim...@googlegroups.com, v...@vim.org

On Dec 2, 2010, at 2:23 AM, bsmile wrote:

>
> Dear members,
>
> I copy something and paste to another vi editor, but the leading white space
> adds up for subsequent lines. For example, what is copied is
>
> aa
> bb
> cc
> dd
>
> when pasted into another vi, what I get is
>
> aa
> bb
> cc
> dd
>
> Any idea to why this happens and how to solve it?

See :h 'paste'

Israel

Benjamin R. Haskell

unread,
Dec 2, 2010, 5:50:38 PM12/2/10
to vim...@googlegroups.com, v...@vim.org
On Thu, 2 Dec 2010, bsmile wrote:

>
> Dear members,
>
> I copy something and paste to another vi editor, but the leading white
> space adds up for subsequent lines. For example, what is copied is
>
> aa
> bb
> cc
> dd
>
> when pasted into another vi, what I get is
>
> aa
> bb
> cc
> dd
>
> Any idea to why this happens and how to solve it?

This is becoming a FAQ. 'paste' is one workaround for the problem, but
see my response at:
http://groups.google.com/group/vim_use/browse_thread/thread/b68671e8a397f6e8#d8af3ae5276368f8

--
Best,
Ben

Christian Brabandt

unread,
Dec 3, 2010, 2:27:56 AM12/3/10
to vim...@googlegroups.com

Indeed and there exists already an entry:
http://vimhelp.appspot.com/vim_faq.txt.html#faq-14.14

Your answer contains useful information, that should
be contained in the FAQ as well.

Well, would you mind, sending me a patch, that enhances that entry
with your answer from above?

regards,
Christian

guivho

unread,
Dec 3, 2010, 2:53:24 AM12/3/10
to vim...@googlegroups.com
Hi,

> Indeed and there exists already an entry:
> http://vimhelp.appspot.com/vim_faq.txt.html#faq-14.14

There's an typo in this faq entry! It suggests to read i_CTRL-R_CTRL_O
which of course should read i_CTRL-R_CTRL-O


guivho

Christian Brabandt

unread,
Dec 3, 2010, 3:06:24 AM12/3/10
to vim...@googlegroups.com

Thanks, I fixed it locally. There seem to be another couple of issues,
if I look at the generated web site. I hope to get them fixed soon and
will push my changes to github and the plugin's page at vim.org soon.

regards,
Christian

lainme

unread,
Dec 3, 2010, 8:13:12 AM12/3/10
to vim...@googlegroups.com
If you are running x, you can install gvim and launch vim as vim.gtk in terminal


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

Chris Jones

unread,
Dec 3, 2010, 2:46:35 AM12/3/10
to vim...@googlegroups.com, v...@vim.org

See also

:h 'pt'

cj

bsmile

unread,
Dec 4, 2010, 12:42:27 PM12/4/10
to v...@vim.org

:set paste works nicely. thanks!

I am wondering whether there is an easy way to fix this thing from
happening. Usually the smartindent carries many intelligent things I like,
but it seems to have done too much when pasting multiple lines. What if
change the algorithm a little bit, say, don't apply autoindent when copying
multiple lines of text? This seems to be very reasonable to do since when we
copy a chunk of text, we hope it is copied over without any change.
--
View this message in context: http://vim.1045645.n5.nabble.com/how-to-solve-this-strange-issue-tp3289031p3292335.html

Yegappan Lakshmanan

unread,
Dec 5, 2010, 12:49:05 PM12/5/10
to vim...@googlegroups.com
Hi all,

On Thu, Dec 2, 2010 at 12:23 AM, bsmile <devou...@gmail.com> wrote:
>
> Dear members,
>
> I copy something and paste to another vi editor, but the leading white space
> adds up for subsequent lines. For example, what is copied is
>
>  aa
>  bb
>  cc
>  dd
>
> when pasted into another vi, what I get is
>
>  aa
>    bb
>      cc
>        dd
>
> Any idea to why this happens and how to solve it?
>

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

Christian Brabandt

unread,
Dec 6, 2010, 6:00:30 AM12/6/10
to vim...@googlegroups.com

Thanks, I'll update the FAQ.

regards,
Christian

Christian Brabandt

unread,
Dec 7, 2010, 2:13:32 AM12/7/10
to vim...@googlegroups.com
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.

It is now in the FAQ:
http://vimhelp.appspot.com/vim_faq.txt.html#faq-14.14

regards,
Christian

Reply all
Reply to author
Forward
0 new messages