0

I'm stuck up with a weird problem. I am trying to copy(yy) and paste(p) a line from one file to another (in split screen). It doesn't look it its working. However, yy, p works in the same file and with another file opened in another "tab". Would be really helpful if someone could tell me how to fix this. Spending a lot of time fixing this :(.

Thanks, Omkar

  • is it the same thing when opening the two files with `vim -o file1 file2` ?? – Meninx - メネンックス Jul 11 '16 at 00:30
  • @Menix Yes, it is. – Omkar Manjunath Jul 11 '16 at 00:49
  • 1
    Curious. Using vim 7.3 on Mac OS X 10.11.5, I can use `yy` in one file to yank a single line, and then go to the next file (`:n`) and use `p` or `P` to pull the material yanked. Using `:set all`, there is no information about `clipboard`, so I don't need to use the answer given to achieve the result. That said, `:set clipboard=unnamed` generates no warning and doesn't appear to do any harm to the basic behaviour. 'Tis mildly curious: `vim --version` specifies (in part) `Normal version without GUI. Features included (+) or not (-): … -clientserver -clipboard +cmdline_compl…`. – Jonathan Leffler Jul 11 '16 at 02:19
  • @JonathanLeffler I am running Vim 7.4 on linux red hat 6.5. `vim --version` specifies `Huge version with GTK2 GUI. Features included (+) or not (-): ... +clientserver +clipboard +cmdline_compilation` – Omkar Manjunath Jul 11 '16 at 14:40
  • Interesting. I've not seen a problem with yank buffers, unnamed or named, not being preserved as I switch files, though it is easy to lose the unnamed type by doing a different edit, of course. I've no extra information on whether it is a subtle change in Vim 7.4 or just an artefact of your configuration. I don't know whether you have add-ons that might make a difference; for all practical purposes, I don't have any add-ons (certainly none that I've configured). – Jonathan Leffler Jul 11 '16 at 14:43

2 Answers2

1

This worked: set clipboard=unnamed

  • 1
    You did not mention how you run Vim. If you run different instances of Vim in separate terminal tabs/windows or in different screen/tmux windows/panes yanking/pasting from one instance to another won't work with default settings. It'll work only between buffers of the same Vim instance. Setting `clipboard=unnamed` makes Vim use system clipboard when you yank to default (unnamed) register, that's why it works for you with this setting. – Paul Jul 11 '16 at 15:47
  • I am running vim on the same terminal. I had opened two tabs in vim and in one of the tab i had opened two files in a split screen. I never faced this in previous version of vim though. Anyways problem solved. This even solved my problem of copy pasting text from vim in linux to windows as it used system clipboard. Thanks for the help again ! – Omkar Manjunath Jul 12 '16 at 16:58
0

You could also use a named buffer. If you yank with "ayy and put with "ap you can yank and put from any buffer to any other buffer in your vim session. You can use any other letter instead of a as the name of the buffer.

lwassink
  • 1,595
  • 13
  • 16