How to select complete file in vi, to be pasted in gedit?
Solution 1
Not sure if vi
is required for this operation.
There is xclip
utility that allows you to copy anything from console output to x server clipboard.
You should specify DISPLAY=:0.0
environment and execute it like this:
cat file | xclip
or for remote file
ssh remote "cat file" | xclip
Or from vi
(note, that this way will temporaly clear vi buffer content, to revoke it press Esc
+ u
, data will stay in X cilpboard):
:%!xclip
Now you're able to paste it anywhere with middle mouse button (note, that CTRL+V
or shift+ins
won't work).
Solution 2
Rather than yanking into the a
register yank into the *
or +
register to
yank the file contents into the X clipboard using one of:
:%y*
:%y+
This does require that you're using a copy of vim that has X support compiled in and is able to connect to your X server. Which of those works better for you will depend on which type of clipboard the target editor uses.
You can even have one of those registers used as the default for yank and paste
operations by including one of the following in your .vimrc
file:
set clipboard+=unnamed
set clipboard+=unnamedplus
Solution 3
If you're regularly finding yourself needing to use both Vim and gedit together, you should probably switch to gVim, the GUI version of Vim.
It seems you're using Ubuntu where gVim isn't installed by default. Use this command to get it:
$ sudo apt-get install vim-gnome
There's also vim-gtk
which doesn't depend on Gnome, but since you're using gedit, you must be using one of the Gnome-based versions of Ubuntu.
Related videos on Youtube
user13107
Updated on September 18, 2022Comments
-
user13107 over 1 year
I know that doing
%y a
will yank complete file into registera
. However this doesn't help in pasting the file content in another text editor (say gedit). What alternative is there for doing so?-
Admin about 11 yearsDid you compile VIM with
X
support? -
Admin about 11 yearsRead in the file from
gedit
? At least that's what I'd do the other way around.
-
-
Bernhard about 11 yearsI get the following error message when using your solution:
E488: Trailing characters
-
user13107 about 11 years
:%!xclip
didn't work. It just deleted all the text in the file invi
. -
rush about 11 years@user13107 actually it works (all data are in clipboard), unfortunately all text is deleted. I'll put it the answer. Thanks.
-
user13107 about 11 yearsIs there a command line alternative to middle mouse button?
-
rush about 11 years@user13107 use
xclip -o
for that.