Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to paste from buffer in ex mode of vim?

Tags:

linux

vim

buffer

I am having a problem in copying certain text from a file then copying it to a new split window.
3yy|new|p

in command mode its working

as when i press

'p' in split window after copying its working

like image 355
Tushar Mishra Avatar asked Oct 24 '12 06:10

Tushar Mishra


People also ask

How do I paste from buffer?

The Clipboard task pane holds many of the last images and text you copied or cut. Note: You can still do simple cut, copy, and paste the way you're used to, either by using the buttons on the ribbon or the keyboard shortcuts CTRL+X (Cut), CTRL+C (Copy), or CTRL+V (Paste).

How do I paste in vim mode?

Once you have selected text in Vim, no matter whether it is using the yank or the delete command, you can paste it in the wanted location. In Vim terminology, pasting is called putting and the function is utilized with the p command. Using this command pastes the selected text after the cursor.

How do I paste from clipboard in Vim?

When using Vim under Windows, the clipboard can be accessed with the following: In step 4, press Shift+Delete to cut or Ctrl+Insert to copy. In step 6, press Shift+Insert to paste.


Video Answer


2 Answers

I understand that you want to:

  1. yank the current line and the two lines below in the current buffer,
  2. open an empty buffer in a new horizontal split and
  3. paste those three lines in the empty buffer.

Is that correct?

What I don't get is why you would want to do it from Ex mode while it's so easy (and working) in normal mode:

3yy
:new<cr>
p

I think that you are confusing ex mode, accessible with Q and command mode, accessible with :. You probably also confuse the :p[rint] command and the :pu[t] command.

Do the following from normal mode:

:.,+2y|new|put!

It may be helpful to know that you can also directly write those three lines to a file with:

:.,+2w filename
like image 189
romainl Avatar answered Sep 29 '22 11:09

romainl


You can use one of the following to copy from the clipboard in Vim:

"+p

"*p

SHIFTINSERT

Which one you use depends on your environment.

If you're using gVim or MacVim, you'll want "+p

If you're using Vim from the command line, you'll want "*p

If you're in insert mode or ex mode (I think) you use SHIFTINSERT

By insert I mean the key over by HOME, PAGE UP, and DELETE

Explanation:

  • " means you're going to specify a register
  • there are 26 custom registers - 1 for each letter
  • there are many other registers (see this)
  • + or " refers to the unnamed buffer, which represents the system clipboard
  • p is the normal put command

More info on buffers:

If you want, you can store different text in different buffers.

To yank 3 lines to the buffer named x use this:

"x3yy

To paste the contents of the buffer named y above the cursor:

"yP

like image 36
jahroy Avatar answered Sep 29 '22 11:09

jahroy