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.
4 Answers
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 for
:set paste
. Didn't know that, every time I had to indent the lines by myself.– YamanekoCommented Nov 9, 2012 at 21:12
Do Vim and PHPStorm are on the same machine?
Is Vim compiled with clipboard support? :echo has('clipboard')
should return 1
.
-
They are on different machine. But I've opened vim in staging server through ssh. Commented Oct 30, 2012 at 10:33
-
1That'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.– romainlCommented 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) 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.– romainlCommented 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.– ZyXCommented Oct 30, 2012 at 10:59
Try "*p
. There are other special registers that can be used, as explained in :h clipboard
.
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
another editor
?