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 right-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.
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).
If you want to copy paste contents within the same file, use yank and paste.
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.
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 calling vim from the terminal, the same way you did before. This time when you check you should 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.
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. I hope this helps.
With Vim 8+ on Linux or Mac, you can now simply use the OS' native paste (ctrl+shift+V on Linux, cmd+V on Mac). Do not press i for Insert Mode.
It will paste the contents of your OS clipboard, preserving the spaces and tabs without adding autoindenting. It's equivalent to the old :set paste, i, ctrl+shift+V, esc, :set nopaste method.
First, check if your vim has clipboard support installed
:echo has('clipboard')
If it returns 1 you do have clipboard support
To copy to the clipboard you have to either select your target, let's say a paragraph vip and then "+y, which means to the register + copy the selected portion or you can simply type in normal mode: "+yip, which means: to the register + copy inner paragraph.
To paste from the clipboard in normal mode you can:
"+p
On insert mode you can simply Ctrl-rCtrl-o+. Tha will insert your clipboard content and preserve all indentation as it is on the clipboard.
If you want to copy the whole buffer to the clipboard you can:
:%y+
% ........ the whole file
y ........ yank (copy)
+ ........ to the clipboard
To copy the last command to the clipboard:
:let @+=@:
To copy the last search to the clipboard:
:let @+=@/
to copy from the mark "a" until the mark "b" to the clipboard:
:'a,'b y+
To test any function that is on the clipboard you can
:@+ (and then type Enter)
:call FunctionName() (and then type Enter)
To see what is on the clipboard:
:reg +
To copy all lines that have "pattern" to the clipboard you can:
:let @a=""
:[range]g/pattern/y A
:let @+=@a
:let @a="" ............ cleanses the register 'a'
:[range]g/pattern/y A append to the register A every line with pattern
:let @+=@a ............ copy register 'a' to the clipboard
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 right-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.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).
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)
If you want to copy paste contents within the same file, use
yank
andpaste
.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 pressp
to paste it.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:
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 calling vim from the terminal, the same way you did before. This time when you check you should 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.
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. I hope this helps.
Use the center button of the mouse to insert text you've highlighted elsewhere.
It is useful when you don't have access to your system clipboard (for example, in a remote SSH session).
Must be in edit/insert mode for Vim.
Once you enter vi, press
i
to get into insert mode, right click into terminal, click paste.Detailed instructions to copy/paste lines of text in vi using
yank
andput
(use the following in the command mode of vi)
Copy (YANK)
To copy one line in vi:
yy
or typeY
To copy 2 lines in vi:
2yy
or type2Y
(likewise, any number of lines can be copied)
To copy all lines from the current location to the end of the file:
yG
To copy all text from the current location to the end of the current word:
yw
To copy all text from the current location to the end of the line:
y$
Paste (PUT)
To paste text in the clipboard - after the location of the cursor:
p
To paste text in the clipboard - before the location of the cursor:
P
With Vim 8+ on Linux or Mac, you can now simply use the OS' native paste (
ctrl+shift+V
on Linux,cmd+V
on Mac). Do not pressi
for Insert Mode.It will paste the contents of your OS clipboard, preserving the spaces and tabs without adding autoindenting. It's equivalent to the old
:set paste
,i
,ctrl+shift+V
,esc
,:set nopaste
method.You don't even need the
+clipboard
or+xterm_clipboard
vim features installed anymore. This feature is called "bracketed paste". For more details, see https://stackoverflow.com/questions/2514445/turning-off-auto-indent-when-pasting-text-into-vim/56781763#56781763I had an issue, because my Vim installation was not supporting the clipboard:
I installed vim-gnome (which supports the clipboard) and then checked again:
Now I am able to copy and paste using "+y and "+p respectively.
First, check if your vim has clipboard support installed
If it returns 1 you do have clipboard support
To copy to the clipboard you have to either select your target, let's say a paragraph
vip
and then"+y
, which means to the register+
copy the selected portion or you can simply type in normal mode:"+yip
, which means: to the register+
copy inner paragraph.To paste from the clipboard in normal mode you can:
On insert mode you can simply Ctrl-rCtrl-o+. Tha will insert your clipboard content and preserve all indentation as it is on the clipboard.
If you want to copy the whole buffer to the clipboard you can:
To copy the last command to the clipboard:
To copy the last search to the clipboard:
to copy from the mark "a" until the mark "b" to the clipboard:
To test any function that is on the clipboard you can
To see what is on the clipboard:
To copy all lines that have "pattern" to the clipboard you can: