For example, when I yank some text from vim, then :wq
, and open a new file. When I try to paste the text I just yanked, it doesn't work. So how to yank text between files?
4 Answers
use "+y
to send the yanked text to the clipboard, and "+p
to paste it into the new file.
So if I have a file named A that contains abcdef
and I (in visual mode) select def
and then press "+y
while in normal mode. I have just copied def
to the system clipboard. Now I can open up a file named B and (while in normal mode) press "+p
the text def
will be pasted into file B.

- 4,833
- 3
- 26
- 40
-
Note that this only works when your copy of Vim is compiled with clipboard support. Not sure? Try `:echo has('clipboard')`. If `1`, you have it. If `0`, you don't. – ravron Jul 30 '13 at 21:54
-
@Riley, you can also find out with `:version` and then see if `clipboard` has a little plus sign (`+`) in front of it. – Alexej Magura Nov 27 '13 at 04:26
-
definitely, but I find that it's a bit of a pain to try to read through that feature list. Your call though! – ravron Dec 02 '13 at 00:42
-
-
fyi on ubuntu you need to now (20.0) install vim-gtk to get the clipboard option – Goblinhack May 28 '21 at 08:06
Don't quit the editor after writing with :wq
Instead, just write the file with :w
and then edit the new file with :e file
. Or Edit both at the same time by splitting with :sp file
and ^W
to switch between the screens.

- 10,348
- 25
- 38
- if you have X11/windows, you could use
"+y
or"*y
to yank. and same register to paste. - don't do
:wq
and thenvim newfile
. do:e newfile
in same vim. then you could yank and paste between buffers. just pressy
andp
- if you work on tty or via ssh, and don't want to do (2) either, you could save yanked part to a file, in newfile read the file.
I recommend the (2) option.

- 189,393
- 32
- 233
- 301
-
-
@OneZero did you try `:h` them or test the both? open your vim, then press `Q`, now you type `e` or `o`, you see difference. – Kent Jul 30 '13 at 22:04
Vim has the capability of viewing multiple files at once. Use the :sp *file_name*
"split" or :vs *file_name*
"vertical split" commands to view another file in the same terminal.
Navigation between open file windows is simple: press Control_key + w
and then either 'h', 'j', 'k', or 'l' to move the cursor to the file window to either the left, the bottom, the top, or the right of the current window. Simply 'yank' the text that you mean to copy in one terminal window, move to the terminal window containing the file that you mean to copy into as described above, and 'put' the text at the cursor location as usual.
By the way, you may use the :wqa
command to close all open terminal windows and write changes made to the open files to the disk.

- 233
- 2
- 7