2

I've a text file opened in another editor and want to copy some text from that file to another file opened in vim editor. I tried google and found "+p. But it's not working. It is pasting the last line that I removed using dd in the same file.

3
  • which is the another editor? Commented Oct 30, 2012 at 10:18
  • Another editor is phpstorm IDE.
    – Shwetanka
    Commented Oct 30, 2012 at 10:20
  • 1
    Hmm, have you normal terminal paste (Ctrl-Shift-V, or middle mouse button) in the insertion mode working? You may need to :set paste to avoid formatting problems... Commented Oct 30, 2012 at 10:51

4 Answers 4

4

To paste from clipboard, go to insert mode of VIM and then press

ctrl+shift+v. 

If you want the indenting to be maintained, for e.g, if you are copying a code, then you can save that too, by enable the paste option. To do that, write:

:set paste
1
  • +1 for :set paste. Didn't know that, every time I had to indent the lines by myself.
    – Yamaneko
    Commented Nov 9, 2012 at 21:12
2

Do Vim and PHPStorm are on the same machine?

Is Vim compiled with clipboard support? :echo has('clipboard') should return 1.

5
  • They are on different machine. But I've opened vim in staging server through ssh.
    – Shwetanka
    Commented Oct 30, 2012 at 10:33
  • 1
    That's where your problem is: the distant Vim can't use your local clipboard. Use the netrw plugin to edit locally a distant file or work locally and use SFTP or some VCS to sync files with the server.
    – romainl
    Commented Oct 30, 2012 at 10:39
  • But if I use right click and paste then it pastes in the file? How does that happen?(On ubuntu terminal)
    – Shwetanka
    Commented Oct 30, 2012 at 10:43
  • 5
    "Right click -> paste" is a feature of your terminal, not of Vim. Both programs can only access their host system's clipboard. "+p is a Vim feature so it's only aware of the server's clipboard if any. "Right click -> Paste" is a feature of your terminal so it's only aware of your local clipboard. But you are using your local terminal to send input signals to your distant server and, in that context, "Paste" works more or less like typing a lot of characters in one go. The clipboards are still separate, though, and you can't use "+y/"+p to yank/put stuff to/from your local clipboard.
    – romainl
    Commented Oct 30, 2012 at 10:58
  • 1
    @Shwetanka Terminal emulator is feeding the characters of the clipboard to the pseudo-tty it has opened (they then appear in stdin), which are then caught by ssh and are fed to the pseudo-terminal opened by ssh on remote machine. It is terminal emulator here who is using clipboard, not vim and not anything on the remote end.
    – ZyX
    Commented Oct 30, 2012 at 10:59
1

Try "*p. There are other special registers that can be used, as explained in :h clipboard.

1

Copy the text from your other editor using

Ctrl+c.

Open your vim editor. Type the command

:set paste

Now press i to enter Insert mode and copy the text using Ctrl+v

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