I access a sever over ssh on which I run vim for editing files. When I try to yank text from vim into an editor locally on my mac (lion) either with y OR "+y it does not work. I end up with the text I copied last locally. It does work if I just use p within vim alright.
相关问题
- Xcode debugger displays incorrect values for varia
- JavaScript File Transfer SSH
- Is there a way to report errors in Apple documenta
- Advice for supporting both Mac and Windows Desktop
- Emacs shell: save commit message
相关文章
- 如何让 vim 支持 .cshtml 文件的代码高亮
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- Check if directory exists on remote machine with s
- Auto-save in VIM as you type
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
Had this problem - log in from OSX over SSH to a linux box and cannot copy text from a file, opened with vim.
My workaround is
:set mouse=i
By default mouse is enabled in all modes. When you set it to be enabled only in Insert mode you can scroll around and copy when you are not editing (normal mode) but when you start editing (by hitting the I or Insert key) and enter insert mode the mouse acts as cursor placement and you cannot copy from terminal.
You can set that option in ~/.vimrc
See :help mouse for more information about the values you can set and the modes.
Yanking within
vi
in a terminal to which you ssh'd into copies the lines into vi's internal buffer on the remote machine, not into your Mac's clipboard.Use your mouse. :)
To expand on Ray's answer…
When you are using Vim on a remote server via SSH, everything you do in Vim is done on the remote server. The remote server and the remote Vim that you are running on it have zero practical knowledge of your local computer and its system clipboard.
Because of that,
y
will never put the yanked text in your local clipboard.In order to copy a chunk of text from the remote Vim to your local machine's clipboard you have three options:
Select the text with your mouse and hit Cmd+C like in any Mac OS X application.
Obviously, it seems to be the easiest but it has at least three limitations:
It is limited to the current screen. If the text you want to yank is not displayed entirely you won't be able to copy all of it.
It doesn't play well with
set mouse=a
. With this option, any attempt to select something with the mouse will result in a visual mode selection which can't be copied with Cmd+C. As a workaround, you can use Alt+mouse to select the text without entering visual mode or simply remove this setting from your remote~/.vimrc
.Line numbers are copied as well.
Put the yanked text in a temporary file,
scp
it to your local machine and usepbcopy
to put it in your system clipboard.This solution seems to be a little convoluted but it works (and the problem itself is also a little bit convoluted). Over the years I've seen a lot of different implementations ranging from simple one liners to client/server setups. Here is one, feel free to google around for others.
Use X-forwarding to connect your local clipboard to the remote clipboard if available.
Try the other clipboard register -
"*y
.One trick which i use often during copying vim text using mouse if number of lines get little over-flown my screen is to minimize (Cmd + '-') the text. :) Minimize so much that you can not see by eyes but you can copy all the text in one go.
Or, from the terminal, write
less [filename]
to get it written to the terminal. Then start byt selecting with your mouse, while you holddown-arrow
-key down. Then you can select the whole bunch.