8

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

Tushar Mishra
  • 177
  • 1
  • 7
  • This question is better suitable for [http://unix.stackexchange.com](http://unix.stackexchange.com) – SurvivalMachine Oct 24 '12 at 06:41
  • 2
    @SurvivalMachine That discussion has been had: [Vim questions: do they belong to Stack Overflow or Super User?](http://meta.stackexchange.com/questions/25925/vim-questions-do-they-belong-to-stack-overflow-or-super-user) and even [on SU: Are questions about vi, vim, and other clones on-topic here?](http://meta.unix.stackexchange.com/questions/309/are-questions-about-vi-vim-and-other-clones-on-topic-here/311#311). TL;DR vim is welcome as a programming tool – sehe Oct 24 '12 at 14:50

3 Answers3

5

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
romainl
  • 186,200
  • 21
  • 280
  • 313
2

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

Community
  • 1
  • 1
jahroy
  • 22,322
  • 9
  • 59
  • 108
  • Thanks ....but what if i want to store specific lines in buffer...means lines form 3 to 8 ..then which command i should use...?? – Tushar Mishra Oct 24 '12 at 06:47
  • In gVim or MacVim you would use `"+y`. In Vim from the command line you would use `"*y` (or other variations of the yank command). – jahroy Oct 24 '12 at 06:48
  • I tend to use _marks_ when I yank text in Vim. So, to answer your question specifically, I would go to line 3 then press `mx` to place a mark with the name _x_. Then I would move to line 8 and use the following command (in gVim, for example): `"+y'x`. In other words, yank all the text between _mark x_ and my cursor into the buffer named _x_. After doing this you can paste your 5 lines into another program with _CONTROL-V_ or a menu command. Or, all in one command: `3Gmx5j"+y'x` – jahroy Oct 24 '12 at 06:50
  • I've never had that happen to me. These commands should be used from command mode. If you're in _ex mode_ I belive you want to use _SHIFT-INSERT_ to paste. – jahroy Oct 24 '12 at 06:52
  • Re-read my answer... I've been editing it. I mention a couple tricks for _ex mode_, too. – jahroy Oct 24 '12 at 06:54
  • actually what i want to do is something like this...from ex mode.... While editing a file “file1” I want to read of the line nos. 10 to 20 from “file2”. How can I do this? – Tushar Mishra Oct 24 '12 at 06:54
  • Swith to file2, copy the lines, then come back to file1 and paste them. You can open file2 like this: `:e file2`. You can switch between two files with _SHIFT-5_. That's how I would do it. I don't know how to do it from one file in ex mode. That's not a workflow I've ever experienced. I just store text in buffers and jump between files. – jahroy Oct 24 '12 at 06:56
  • @TusharMishra - here's a pretty awesome answer with a bunch of info about registers: http://stackoverflow.com/q/3997078/778118 – jahroy Oct 24 '12 at 07:05
  • No problem... I hope some of that mumbo jumbo actually helped! – jahroy Oct 24 '12 at 07:15
0

p is just vi command, so it should be pu in ex instead. or you can do with double quote, "p or "np. n is for the number in the register of buffer, "2p means the 2nd oldest yank you made.

Mat Watershed
  • 45
  • 3
  • 7