How to copy and paste things between vim and system clipboard
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
On a pretty stock Slackware 12.0, the "set mouse=r" option is all I need to provide. I ran the following test from an Xterm just to make sure (but I'm using Openbox only, not KDE).
Code:
1. mv -i ~/.vimrc ~/.vimrc.bak
2. vim /tmp/tmp.txt
Highlighting in Firefox and middle click pasting into Vim does not work
Highlighting in Vim and middle click pasting into Firefox does not work
3. echo "set mouse=r" > ~/.vimrc
4. vim /tmp/tmp.txt
Highlighting in Firefox and middle click pasting into Vim now works
Highlighting in Vim and middle click pasting into Firefox now works
Click here to see the post LQ members have rated as the most helpful post in this thread.
I am using openSuSE, i had klipper (clip board tool) at the tray. When ever i select some text at any window and press copy ---- then it automatically copied and shown at klipper. Now i can see what are copied. Klipper has history manager. My klipper shows last 7 copied texts.
This is an odd and needlessly complex discussion...
Hold shift while hilighting in vim to copy to the clipboard and then middle-click in any other app. When trying to paste *into* vim, just use Shift+Insert assuming you've copied to the system clipboard (the clipboard situation is very messy by default in Linux and is one of the worst designs IMO...to rectify this in WMs that don't handle this stuff as well as klipper or whatever other tool you may use, I always just set my terminal to copy to the primary buffer. urxvt makes this easy with perl extensions). The set mouse=a/r will work as well but you don't have to change that on-the-fly and exclude yourself from VISUAL mode...just hold shift.
Of course the real reason that this thread exists is that you cannot perform proper copying/pasting in vim using *registers* because it wasn't compiled with --with-x (which is annoying). It works properly in gvim but not in console vim, and the only way to fix this (so the clipboard is accessible using the system register in vim) is by recompiling.
Why has this thread reached so many pages?
[edit] Just checked, and shift+middle click works to paste into vim as well. So just hold shift while doing any standard hilighting/middle-clicking in vim and you're golden, and you can still use visual mode. Of course this is still incredibly stupid since it should have been compiled with --with-x in the first place, but I guess they were trying not to exclude those without X on their system. [/edit]
Thanks T3slider. The Shift modifier works like a charm So I will set mouse to a instead of r from now on. I've no idea why this thread got so loong(Oh, 3 pages). Maybe Shift is broken in the past
1) sudo apt-get install vim-full
2) insert the following into my .vimrc
"""
set clipboard=unnamed
vnoremap y "*y
vnoremap Y "*Y
nnoremap p "*p
nnoremap P "*P
"""
now to copy, I press 'v' to enter visual highlight mode,
highlight the area I want to copy,
and press 'y' to yank it into the clipboard
to paste, I press 'p' from normal/command mode.
----
What this does:
vim uses multiple registers. I'm sure there are some ninjas out there who
switch between registers, but I only use one. the '*' register is the clipboard, so the last 4 commands just specify using that whenever you try to yank or paste.
I dont know if the first line is needed and I don't care.
1) sudo apt-get install vim-full
2) insert the following into my .vimrc
"""
set clipboard=unnamed
vnoremap y "*y
vnoremap Y "*Y
nnoremap p "*p
nnoremap P "*P
"""
now to copy, I press 'v' to enter visual highlight mode,
highlight the area I want to copy,
and press 'y' to yank it into the clipboard
to paste, I press 'p' from normal/command mode.
----
What this does:
vim uses multiple registers. I'm sure there are some ninjas out there who
switch between registers, but I only use one. the '*' register is the clipboard, so the last 4 commands just specify using that whenever you try to yank or paste.
I dont know if the first line is needed and I don't care.
While you undoubtedly happy using Debian Lenny, this is a Slackware forum. A solution that starts off with the "apt-get" command in a Slackware forum thread won't be very relevant. Not to mention other differences between Slackware and Debian.
Well I'm on Kubuntu I put
set clipboard=unnamed
in .vimrc - and it enables me to interact with clipboard. All copy/paste commands - like dd - all work well through the clipboard.
Could this be a case of imagining the solution rather than solving the need?
If the need is "I want to copy text from vim running in an xterm to the clipboard and vice versa", it can be done using xterm's clipboard copy and paste facilities. For copying from vim, this method is limited to a screenful at a time and line numbers have to be off, though
Could this be a case of imagining the solution rather than solving the need?
If the need is "I want to copy text from vim running in an xterm to the clipboard and vice versa", it can be done using xterm's clipboard copy and paste facilities. For copying from vim, this method is limited to a screenful at a time and line numbers have to be off, though
Install xclip (though I think Slackware comes with it or something similar, xclipboard perhaps).
Copy anything from your X application, switch to Vim. :r!xclip -o and it will read the content into the buffer.
If you want to copy from Vim, simply :w !xclip (the space between w and ! is important) and it will write the buffer into xclip, or any other program. visual selection followed by :!xclip works too but it deletes the selected text.
Install xclip (though I think Slackware comes with it or something similar, xclipboard perhaps).
Copy anything from your X application, switch to Vim. :r!xclip -o and it will read the content into the buffer.
If you want to copy from Vim, simply :w !xclip (the space between w and ! is important) and it will write the buffer into xclip, or any other program. visual selection followed by :!xclip works too but it deletes the selected text.
Many thanks !!
this is alsmost working
Code:
function Xclipcopy()
:w /tmp/clip.txt
silent execute '! cat /tmp/clip.txt | xclip -i '
endfunction
" COPY To X11 CLipboard
" vmap <F5> :!xclip -f -sel clip<CR> <----- not working!!!!
" may work too? map <F7> :-1r !xclip -o -sel clip<CR> <--- not working
vmap <F5> :call Xclipcopy()<cr>
" below this is very well working
" Paste From X11 CLipboard
" map <F6> :w !xclip<CR><CR>
" vmap <F6> "*y <-- not working
map <F6> :r!xclip -o<CR>
vmap <F6> :r!xclip -o<CR>
" hey, note, here we talk about vim (not gvim)
Code:
screen --version####################
Screen version 4.00.03jw4 (FAU) 2-May-06
only COPY with F5 is not working !!
xclip -i shall do it
cat /tmp/file | xclip -i shall make it but how...
###
:!xclip NOT working
The text is selected with v in visual
this is brillantly not working since it tries to save to file.
Code:
~$ vim /tmp/tetimedia:~[No write since last change]
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.