Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lets say I log in to bash, open a file in vi, then using alt-f2 I open a new terminal. After logging in I navigate to a second file and open that in vi. How can I CnP between these two files?

I found this from I'm not familiar with this command shift-8-y-y. I follow the vimtutor and use virtual mode. I tried this sequence and was unsuccessful.

And, I read this about registers. I found a mention of using double_quote-p to 'put' or paste the register, but this does not work in a different file. The second file reported the register empty.

Alternatively, I read in the VIM docs, it is possible to open multiple files under split screens. This may be a course to a solution. The need I often encounter has me navigating in a different bash window to find a file, then wishing to copy between the two. Whereas, I imagine, a split VIM window useful for files in the same directory.

share|improve this question
I think the two sessions would have to be in the same terminal to use copy and past in vi. You can try an experiment where you have two terminals open, use yy to copy a line into a buffer and see that pasting in each window results in the content that was yanked in that window. You could of course use the windowing enviroment to copy and paste (say CNTL-C and CNTL-V and that would work if you put vi into its correct mode before the pasting). – Peter Grill Jun 15 '11 at 22:19
FYI, you don't really "log into bash", and there is no such thing as a "bash window". Do you mean Linux console? – Keith Jun 15 '11 at 23:29
(>_<) Linux console sounds good. And, to "open a new console" and "I have multiple consoles open." would also be correct terminology? Is console synonymous with terminal? To me, ANYTHING which displays on a monitor is generically a window. ehehe. – xtian Jun 16 '11 at 0:41
Consoles and terminals are not synonymous in the Unix/Linux worlds. You're talking about Linux "virtual terminals". – JdeBP Jun 16 '11 at 9:38
up vote 1 down vote accepted

You cannot do it unaided in a standard generic way with the vim you have.

Firstly make sure you have a good version compiled and installed on your distro.

Then I would suggest either using gvim with separate windows, or using vim -o to open multiple files and just between the frames using ^W^W to switch and then copy and paste.

share|improve this answer

It's no wonder that it didn't work for you. You're mis-spelling the commands. It's not shift-8-y-y. Nor is it double_quote-p. The commands are:

  • Yank current line to X11 clipboard: "+yy
  • Paste from X11 clipboard: "+p
  • Yank current line to X11 (primary) selection: "*yy
  • Paste from X11 (primary) selection: "*p

Modify the motion part according to taste. vim has to know that an X server is there, of course. So you'll have to explicitly tell it where the X server is and what display on that server to use if you aren't running it from within an X session where it implicitly inherits the DISPLAY environment variable and so forth.

share|improve this answer
This is running on a laptop which boots to the terminal. Are you referring to what garyjohn called the "X Windows system clipboard" when you refer to the X server? – xtian Jun 16 '11 at 0:46
And, I tried the commands "+yy and "*yy; when I type "+ together then y I get "E78 unknown mark" error; If I type "+y then y I get E20 Mark not set error. I am close? – xtian Jun 16 '11 at 0:47
You're still mis-spelling the commands. I wrote " yet you're typing '. What garyjohn says about different binaries compiled with and without X support is important, too. – JdeBP Jun 16 '11 at 9:22
Then what is *? – xtian Jun 16 '11 at 17:54

You may want to install the "general purpose mouse" (gpm) package, which allows the use of mouse copy-and-paste without a GUI.

share|improve this answer
this will not work with larger buffers... And when pasting it may reformat as-you-type undesirably. – Marius Jun 15 '11 at 23:19
If you're worried about the formatting, vim in vi emulation mode may not have the 'paste' option, but still has the = operator. – evaryont Jun 16 '11 at 5:32

The vi that's included in many GNU/Linux distributions is a tiny version of Vim which has been compiled without many of Vim's features, including the interface to the X Window System's clipboard. Even their terminal-mode vim program is often built without support for X. Without support for X, your vi and vim will be unable to access the clipboard and you will be unable to copy and paste between different instances of the program.

One solution to that is to run the gvim program in terminal mode by using the -v option, as

$ gvim -v your_file

To avoid typing that, or forgetting to type that, every time, you could add these aliases to your ~/.bashrc file:

alias vim='gvim -v'
alias vi='gvim -v'

Once you're using a version of Vim compiled with support for X, you can use the commands described in JdeBP's answer. You can also read about those command's in Vim's internal user manual and reference manual by executing

:help 04.7
:help 09.3
share|improve this answer
To use the X system's clipboard wouldn't X need to be running, then? If I'm using X I don't suffer this problem, I can simply use the mouse :P – xtian Jun 16 '11 at 18:15
Yes. When you wrote about opening a new terminal and using different bash windows, I overlooked that you were using Alt-F2 from a console to open another console and assumed that you were opening terminal windows in some sort of X window manager. My mistake. As for the mouse, I try to avoid using it, so I copy and paste between my various Vim windows with the yank and put commands. – garyjohn Jun 16 '11 at 18:31

Since you seem to be using the console (no X windows, so many of the other answers are not relevant) you might just edit the multiple files in one vim session. Try :split ... to edit the two files at once and use vim's cut buffers to move text between them.

Alternatively you can use gpm, and cut and past between consoles.

share|improve this answer

I don't know about vi, but with emacs you can have the other terminals attach to the primary emacs session with emacsclient and then they will all share the same kill ring ( and buffers, etc ) so you can kill and yank between them.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .