Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I tried using CTRL + V for pasting contents in a VI editor document, but CTRL + V is not interpreted as a paste.

share|improve this question
6  
Just a note, the main reason to use Vi is because Vim isn't installed. If you have Vim installed, it's probably worth using that instead. There isn't really an advantage to Vi besides that it is already present on every Unix install. The best way to learn Vim in my opinion is to open your terminal emulator (not from within Vim) and type vimtutor It will get you up to speed to where it's usable to you in about 45 minutes. – Ben Mordecai Feb 16 at 18:58

6 Answers

up vote 21 down vote accepted

First, make sure you're in edit mode (press i). Then you can paste with Ctrl+Shift+V, if you're in a terminal emulator like gnome-terminal (or select "Paste" from the left-click menu).

You can also type :set paste in vim before you paste to disable automated indenting, etc. Then :set nopaste after you've pasted the content.

Also check this question on stackoverflow.com for more information.

If you want to copy/paste lines in vim (as opposed to pasting clipboard content), you'll want to check out the yank command. Here is a cheat sheet that might help.

share|improve this answer
I think if you have mouse cursor on, you cannot paste using Ctrl+Shift+V. – Alvin Wong Feb 16 at 14:34
6  
Just a note, the I is case-sensitive. The lowercase i is the normal way of entering insert mode. Capital I brings the cursor to the beginning of the line and then enters you into insert mode. – Ben Mordecai Feb 16 at 19:01
@BenMordecai well pointed out, thanks, fixed. – Attila O. Feb 17 at 16:09

Vi (and Vim) works very differently compared to a normal text editor such as Gedit. It also has a pretty steep learning curve. If you want to learn some basic commands, start with this interactive tutorial.

However, to answer you question. The system clipboard's content can be accessed through the plus register. So to paste something from the system clipboard you can, from the Normal mode, press: "+p (Not at the same time, but one after another).

share|improve this answer
2  
This is something I did not know till now. Also, +1 for linking yet another awesome vim tutorial. – Attila O. Feb 16 at 8:37
12  
Speaking of learning curves for editors, there is the "classical learning curves for some common editors", blog.thilelli.net/public/store/attached/curves.jpg. – hlovdal Feb 16 at 15:02
In GNOME Terminal, the short-cuts for copy and paste are Ctrl-Shift-C and Ctrl-Shift-V, respectively. – Flimm Feb 23 at 9:17

Use the center button of the mouse to insert text you've highlighted elsewhere.

Useful when you don't have access to your system clipboard (eg. in a remote ssh session)

Must be in edit/insert mode for vim

share|improve this answer
  1. If you want to copy paste contents within same file, use yank and paste. I believe you have known this.

  2. If you want to copy paste contents across terminals, open the first file, yanking the text you want, then open your second file within vim (e.g. :tabnew /path/to/second/file) and press p to paste it.

  3. If you want to copy paste contents from vim to an external program, you need to access the system clipboard. I assume you use Ubuntu. The GUI version of vim always has clipboard support, however, if you like to use Vim from a terminal, you will have to check for X11-clipboard support.

    From the console, type:

    $ vim --version | grep xterm
    

    If you find -xterm_clipboard, you have two options:

    1) Compile vim yourself, with the xterm_clipboard flag on

    2) Uninstall vim, install gvim (vim-gtk or vim-gnome) instead. You can stick to non-gui vim by call vim from terminal, the same way you did before. This time when you check , you will find +xterm_clipborad.

    Now, when you yank some text in the + register inside your vim editor (e.g. "+yy), it also gets copied to the system clipboard which you can retrieve from your external program like gedit editor, by using Ctrl+V.

  4. If you want to copy paste contents from an external program into vim, first copy your text into system clipboard via Ctrl+C, then in vim editor insert mode, click the mouse middle button (usually the wheel) or press Ctrl+Shift+V to paste.

    These are 4 basic copy & paste conditions related to vim, hope this helps.

share|improve this answer
+1 for ':tabnew' option – pl1nk Feb 26 at 17:29

I always use Shift+Insert when I want to paste text into the terminal, works in all terminal programs.

(Which is also the reason why I never get a laptop where you can't press Insert without pressing a secondary key)

share|improve this answer
Vi/Vim != terminal ;) – 0xC0000022L Feb 17 at 17:01
ok ok, but it still works :) – Magnus Jonsson Feb 17 at 17:11

Once you enter vi, press i to get into insert mode, right click into terminal, click paste.

share|improve this answer
I thought was lower-case i. What does upper-case I do? – Flimm Feb 23 at 9:16
@Flimm that was already explained in a comment by Ben Mordecai on another answer. – sierrasdetandil Feb 23 at 19:42
I've edited the answer to be lower-case i. Upper-case I moves the cursor to the beginning of the line before entering insert mode, which is not needed here. – Flimm Feb 23 at 20:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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