I know that doing %y a will yank complete file into register a. However this doesn't help in pasting the file content in another text editor (say gedit). What alternative is there for doing so?

  • Did you compile VIM with X support? – daisy Mar 15 '13 at 6:44
  • @warl0ck I didn't do anything special apart from apt-get install. – user13107 Mar 15 '13 at 6:52
  • Read in the file from gedit? At least that's what I'd do the other way around. – vonbrand Mar 15 '13 at 13:21

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):


Now you're able to paste it anywhere with middle mouse button (note, that CTRL+V or shift+ins won't work).

| improve this answer | |
  • :%!xclip didn't work. It just deleted all the text in the file in vi. – user13107 Mar 17 '13 at 7:34
  • @user13107 actually it works (all data are in clipboard), unfortunately all text is deleted. I'll put it the answer. Thanks. – rush Mar 17 '13 at 9:19
  • Is there a command line alternative to middle mouse button? – user13107 Mar 17 '13 at 16:34
  • @user13107 use xclip -o for that. – rush Mar 17 '13 at 16:40

Rather than yanking into the a register yank into the * or + register to yank the file contents into the X clipboard using one of:


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
| improve this answer | |
  • 1
    I get the following error message when using your solution: E488: Trailing characters – Bernhard Mar 15 '13 at 6:28

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.

| improve this answer | |

Perhaps try,

behave mswin,

And use ^C / ^V to copy and paste contents, not sure if this is what you wanted

| improve this answer | |

I've solved this by adding the following alias to my .bashrc

alias vim='gvim -v'

and in .vimrc set the clipboard to unnamedplus

set clipboard=unnamedplus

Then yank:ed text is copied to the global buffer, and can be pasted in gedit with ctrl+v. Globally copied text can also be pasted using the vim p command

| improve this answer | |

In normal mode, ggvG$ will select all text and save it in the "* register, then go to gedit and click middle mouse, the text will be there.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.