rkitover / vimpager

Use Vim as PAGER
http://www.vim.org/scripts/script.php?script_id=1723
Other
776 stars 72 forks source link

Can't copy-paste #45

Open cdlm opened 12 years ago

cdlm commented 12 years ago

When trying to copy text from vimpager, I get E481: No range allowed, and nothing goes to the system pasteboard. It's the same with vim shortcuts (e.g. yy) and with mouse selection and Command C.

This is with iTerm 2 on Mac.

rkitover commented 12 years ago

Commands like e.g. yy will not work, because less.vim overrides some common vi commands to be used for movement.

As for mouse selection, it will depend on whether or not you have:

set mouse=a set ttymouse=xterm2

in your .vimrc, to turn on terminal mouse support.

If you have:

set mouse=

then terminal vim does not use the mouse, and you can select text normally.

If you have mouse turned on, selection using the mouse goes to register * instead of the clipboard, to make it go to the clipboard as well use:

set clipboard=autoselect

I should probably add this command to vimpager.

The advantage of mouse=a clipboard=autoselect is that you can still use trackpad scrolling and copy text with it as well.

Note that you don't need to press cmd-C to copy, it is sufficient to just select the text for it to go to the clipboard.

If for some reason this code does not work for you in your .vimrc:

set mouse=a set ttymouse=xterm2 set clipboard=autoselect

you can try disabling mouse support while in vimpager, using something like this instead:

if !exists("vimpager") set mouse=a set ttymouse=xterm2 set clipboard=autoselect else set mouse= endif

that will turn off mouse support (including the very convenient scrolling support) and just let you select text like from the terminal.

Another option is to hold down the option key when you select text, that overrides the application's use of the mouse in iTerm2 and lets you select any text normally.

I don't know what exactly is giving you the "No range allowed" error, I don't get that in any case.

Please let me know if this information was helpful in resolving your issue.

cdlm commented 12 years ago

Thanks!

I did have mouse=a but clipboard=unnamed (that was explicit in my .vimrc so there's a change I wanted it that way… but we'll see) and ttymouse=xterm (was that an important difference?).

I didn't know about the option key trick, that nice to know as well :)

rkitover commented 12 years ago

I'm not sure if ttymouse=xterm versus ttymouse=xterm2 is important for iterm2, but I would recommend ttymouse=xterm2 as that is generally the right option for modern terminals.

You can also set clipboard to both of these options as follows:

set clipboard=unnamed,autoselect

I'm curious what is giving you the "No range allowed" error, can you give me some more details on what you are doing when you get that error?

cdlm commented 12 years ago

That error happens when I make a selection (e.g. vw or V) then copy (y).

yy does have a really strange behavior

jdumas commented 12 years ago

Hi. Same issue here. I'm trying to select text while in vimpager (v. 1.7.5), but I'm unable to paste it elsewhere (in gedit for example). Yet I have set clipboard=unnamed,autoselect and set mouse=a in my .vimrc. The msg E481 is displayed when I do the following: open a text with vimpager, select something with the mouse, and then press q to quit (I have to press it twice to actually quit).

For the record my .vimrc looks like that: http://pastebin.com/Jdagm4xH

I hope you'll be able to reproduce this.

rkitover commented 11 years ago

cdlm:

you cannot select text using vim movement commands while vimpager, it is only meant for using with less keys for scrolling and searching etc.

jdumas:

make sure your vim binary is linked against X11 (ldd which vim), vim can be compiled without X11 support in which case it will not have access to the X11 clipboard, this is also true if you start vim with -X. If you want to use the mouse to select in vim that has no X11 support, make sure to "set mouse=" instead of "set mouse=a", then you can select text the same way as in any other terminal app.

the issue of selecting text then pressing "q" I have reproduced. This happens because selecting with the mouse with mouse=a starts visual mode with a selection, then the selection is passed as a range to the following commands. The quit command does not allow ranges, so we have to add another "q" binding for visual mode that ignores the range, I will try to come up with a fix.

jdumas commented 11 years ago

You were right, the issue was that my vim binary wasn't build with X11 support. I could set mouse= in my .vimrc, but I would have lost mouse scrolling support, which one of the reason I'm using vimpager. Anyway, after installing a gui version of vim from the repositories, everything is working fine (copy-paste and mouse scrolling).

As for the range issue, well I don't know vim well enough to help, but it's not really a big annoyance in use.

Best.

AllisonV commented 11 years ago

What is the rationale for preventing yy usage? Seems like a lot of people here would like it.

rkitover commented 11 years ago

Hi Allison,

the reason vimpager does not allow the yy command is because less.vim, just like less itself, binds y to go one line up.

rkitover commented 11 years ago

I fixed the q with visual selection issue in master, going to see if there are any other quick fixes I can do for a new release.

rkitover commented 11 years ago

Fix for q with visual selection released in 1.7.7.

I'll leave this issue open as the discussion here may be helpful here for anyone confused by the behavior of vimpager.

doctorcolossus commented 9 years ago

I'm having this issue with vimpager in gvim using "let vimpager_use_gvim = 1". I'm sorry if I missed something here, but I read through all the comments and tried clipboard=autoselect (I don't think the ttymouse setting is relevant for me, since I'm not using vim in a terminal emulator). Is there any workaround to be able to copy text without disabling mouse scrolling in gvim?

rkitover commented 9 years ago

You have to use:

set clipboard=unnamed,autoselect

your problem was that you did not include 'unnamed'.

rkitover commented 9 years ago

Did that help?

I am going to put these settings into the init function.

doctorcolossus commented 9 years ago

Thanks, but it did not help. ): I have tried that, as well as "set clipboard=unnamedplus,autoselect". Highlighting text with the mouse still doesn't copy it, and 'y' is remapped.

I realized that I had been using an older vimpager-git version (1.8.2) from the AUR, and that the latest was now available in the community repo. I tried upgrading to that, and then the latest from git, but neither resolved the issue. Instead, I ran into a different issue with the newer versions, so I have to open a new issue for that, which is why I procrastinated on the reply. d-: Sorry for that.

The issue with the newer versions, briefly, is that whereas vimpager-git-1.8.2 was displaying git colors perfectly, the latest versions throw a ton of "E254: Cannot allocate color none. Error detected while processing AnsiEsc#AnsiEsc", and the result is that most colors aren't rendered. It looks similar to doesn't play nicely with git #11 or [AnsiEsc: escape sequence '\x1b1;39m' (bold) not properly recognized #105, so I will read through those the next time I have a moment. For now, I've downgraded back to 1.8.2.

rkitover commented 9 years ago

I fixed this. This is a critical bug and I'll try to do a new release as soon as possible.