You are not logged in.

#1 2012-05-26 16:45:51

xhc
Member
Registered: 2012-02-01
Posts: 113

vim - copy to clipboard without mouse and paste to other application

I can copy & paste in editor vim.. andI know copying with mouse.. how to set vim to select all lines and copy them without mouse and paste it to other application like leafpad with Ctrl+V or with "paste" in options? it is possible in vim?

Last edited by xhc (2012-05-26 18:10:31)


#Awesome window manager

Offline

#2 2012-05-26 16:54:20

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: vim - copy to clipboard without mouse and paste to other application

I do it simply using generic Vim's yanking feature. It should be working if your Vim comes with X support.


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#3 2012-05-26 16:57:01

xhc
Member
Registered: 2012-02-01
Posts: 113

Re: vim - copy to clipboard without mouse and paste to other application

can u pls post what exactly are you doing ?


#Awesome window manager

Offline

#4 2012-05-26 17:02:24

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: vim - copy to clipboard without mouse and paste to other application

Or just bind some key to send the buffer contents to parcellite.  Something like

nmap <F5> :!cat % | parcellite<cr>

Note: I don't use parcellite, so I don't know the proper invocations.

Last edited by Trilby (2012-05-26 17:03:40)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2012-05-26 17:04:19

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: vim - copy to clipboard without mouse and paste to other application

Sure: I press v, select the text, than press y, finally paste the snippets in the target application using Ctrl + v (if pasting into Vim, use p).

The crucial parts of my Vim config are '+clipboard +xterm_clipboard +X11 '.

Oh, and one more thing: in your Parcellite config window, check 'Use Copy', 'Use Primary (Selection)', 'Synchronize clipboards'. Nothing else (e.g. special shortcuts) is required.

Edit: thinking right, writing wrong...

Last edited by bohoomil (2012-05-26 17:36:24)


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#6 2012-05-26 17:34:03

kniren
Member
Registered: 2011-10-12
Posts: 40

Re: vim - copy to clipboard without mouse and paste to other application

Hi there!
You can copy from vim to the clipboard saving the yank into the '+' buffer, this is

"+y

for yanking to the clipboard and

"+p

to paste from the clipboard in vim, so if you just want to copy all text in a file with vim, you can make yourself a macro that contains the following command:

ggVG"+y

Archlinux :: Xmonad
dotfiles | deviantart

Offline

#7 2012-05-26 17:39:53

mhertz
Member
From: Denmark
Registered: 2010-06-19
Posts: 681

Re: vim - copy to clipboard without mouse and paste to other application

Parecelite etc. isn't needed for that...

You have the choise of using either primary selection or clipboard...

For primary selection, you use vim's visual mode to mark text(not yank it, just mark), and then in whatever other app paste primary selection with 'shift+ins'.

For clipboard, you need e.g. the gvim package from the arch repo's, which includes a vim with clipboard support enabled, and then you mark the text and then copy it to clipboard with '"+y', that is 'double-quote+plus+y' and then paste in whatever clipboard capable app with ussually ctrl+v.

Finally, you can configure vim to always yank to clipboard(in addition to primary-selection), so you can mark text, press y, and then ctrl+v in whatever clipboard capable app afterwards; to do that add 'set clipboard=unnamedplus' to your .vimrc. (note, vim clears whatever it self has placed in the clipboard whenever quiting vim, so keep vim open after you have copied from it and untill after you've pasted from it...)

Edit: Beaten by kniren for some of the info smile

Edit2: Using Primary selection with x11 apps also needs either vim from the gvim package, or a custom built one...

Last edited by mhertz (2012-05-26 19:21:08)

Offline

#8 2012-05-26 17:41:50

xhc
Member
Registered: 2012-02-01
Posts: 113

Re: vim - copy to clipboard without mouse and paste to other application

parcellite is not needed.. I just want to copy all lines in vim (sometimes 20 000 lines) with command Shift + V and Shift + G and SOME COMMAND to clipboard which allows me pasting these lines to web browser for example ....   

press v, select the text, than press y, finally paste the snippets in the target application using p. - this runs in vim, thats ok, but not ok in other application :-)

I will try the nmap.... hope it will be run


#Awesome window manager

Offline

#9 2012-05-26 17:49:03

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: vim - copy to clipboard without mouse and paste to other application

xhc wrote:

press v, select the text, than press y, finally paste the snippets in the target application using p. - this runs in vim, thats ok, but not ok in other application :-)

My bad -- see my edit above. wink You need some app to sync clipboards, IMO. This will let you use Ctrl + c / Ctrl + v and 'y' / 'p' to copy / paste between vim and other applications simultaneously.


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#10 2012-05-26 18:06:31

xhc
Member
Registered: 2012-02-01
Posts: 113

Re: vim - copy to clipboard without mouse and paste to other application

hmm .. cant pasting into the leafpad for example ... it marks, it copy, but only in vim ... I have installed vim without other programs.. only basic vim.. and I dont want have gui to vim .-)

Last edited by xhc (2012-05-26 18:06:48)


#Awesome window manager

Offline

#11 2012-05-26 18:10:55

donniezazen
Member
From: Salt Lake City
Registered: 2011-06-24
Posts: 671
Website

Re: vim - copy to clipboard without mouse and paste to other application

I am not sure about your question. I do Ctrl+Insert and everything selected is automatically copied to Parcellite.

Offline

#12 2012-05-26 18:18:52

xhc
Member
Registered: 2012-02-01
Posts: 113

Re: vim - copy to clipboard without mouse and paste to other application

and you select with mouse.. because with mouse it runs... but 20 000lines with mouse?? cant move down with mouse in vim :-)


#Awesome window manager

Offline

#13 2012-05-26 18:20:08

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: vim - copy to clipboard without mouse and paste to other application

xhc wrote:

I have installed vim without other programs.. only basic vim.. and I dont want have gui to vim .-)

If so, you have no X11 enabled in your Vim (see the PKGBUILD and compare Vim vs gVim -- the latter comes with '--with-X=yes' and that flag you need to have enabled to be able to cross-paste between Vim and other apps).

Just rebuild Vim with the said flag and you should get what you want.


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#14 2012-05-26 18:39:28

mhertz
Member
From: Denmark
Registered: 2010-06-19
Posts: 681

Re: vim - copy to clipboard without mouse and paste to other application

Yes, rebuild vim, or just simply install gvim, which includes standard vim also, so you do not have to use the gui(I don't!)...

Then afterwards you need to do what me and kniren previously explained. Also, the macro kniren explained was a nice suggestion to save time in the feuture...

Lastly, as I also explained in my last post, then you can also do what you want with standard vim without x11 support compiled in, by using primary selection, allthough I would recommend vim users to get the "full" vim that comes wih gvim, or to build your own "full" version...

Last edited by mhertz (2012-05-26 19:18:02)

Offline

#15 2012-05-26 18:45:48

xhc
Member
Registered: 2012-02-01
Posts: 113

Re: vim - copy to clipboard without mouse and paste to other application

and only different vim - gvim is in this copying to x applications?


#Awesome window manager

Offline

#16 2012-05-26 18:54:33

mhertz
Member
From: Denmark
Registered: 2010-06-19
Posts: 681

Re: vim - copy to clipboard without mouse and paste to other application

I apologise for my ignorance!

vim compiled without --with-x=yes, also cannot use primary-selection in gui apps!

@xhc

You don't need gvim, vim from the gvim package, or custom-built, can also copy/paste to/from X11 apps, and both needs "+y to copy to clipboard(or 'clipboard=unnamedplus' in .vimrc), instead of using it's own internal buffer(s)...

Last edited by mhertz (2012-05-26 19:00:14)

Offline

#17 2012-05-26 18:55:37

bohoomil
Member
Registered: 2010-09-04
Posts: 2,376
Website

Re: vim - copy to clipboard without mouse and paste to other application

Just for safety reasons, I configure my Vim with three relevant flags: +clipboard +xterm_clipboard +X11 -- as I have already mentioned above. The original Vim was not supposed to be used in the X environment, while gVim was. Therefore only one of them comes with X specific features enabled by default. However, it's possible to reconfigure text-only version of Vim to act like a regular X application, or at least make it able to seamlessly communicate with the X environment and use X resources. I believe if you don't need GUI and only some features of gVim, recompiling Vim is the a thing to be done.

Edit: just for the reference, the configuration I've been successfully using:

    ./configure --prefix=/usr \
      --mandir=/usr/man \
      --with-x=yes \
      --with-compiledby=bohoomil \
      --disable-gui \
      --enable-multibyte \
      --enable-gpm \
      --enable-acl \
      --disable-cscope \
      --disable-netbeans \
      --disable-perlinterp \
      --disable-pythoninterp \
      --disable-rubyinterp \
      --with-features=normal

Last edited by bohoomil (2012-05-26 18:58:24)


:: Registered Linux User No. 223384

:: github
:: infinality-bundle+fonts: good looking fonts made easy

Offline

#18 2012-05-26 23:33:11

/dev/zero
Member
From: Melbourne, Australia
Registered: 2011-10-20
Posts: 1,247

Re: vim - copy to clipboard without mouse and paste to other application

I find it convenient to work with xsel. See here for how to use it with vim.

I couldn't be bothered making up new keymappings so I just do it manually: go into visual mode, select the text you want to copy, then type

:w ! xsel -ib

Offline

#19 2012-07-03 20:26:31

rasch
Member
Registered: 2012-02-23
Posts: 4

Re: vim - copy to clipboard without mouse and paste to other application

Not sure if you found a solution to your issue yet. I use xclip which is very similar to using xsel.
Just install xclip and put the following in your .vimrc but change the <F11> and <F12> mappings if you like.

map <F11> :!xclip -f<CR>    
map <F12> :r !xclip -o<CR>

Make you selection in vim and press <F11> or whatever your mapping is.
Now you can use shift+insert to paste outside of vim or <F12> to paste inside a separate running instance of vim.

Minor problem with this solution (or maybe major if you always write you text files on single lines without line breaks) is that it copies all text from the lines selected even if you only select a partial line.
For example if I have a line that says "Copy this line" and I highlight just the word "Copy", the entire "Copy this line" will be pasted. So far not a problem for me since I rarely copy a partial line, but I just thought I would point it out. This problem also occurs when using xsel.

Offline

Board footer

Powered by FluxBB