Thursday, March 16, 2017

Re: Wierdness in vim

On 2017-03-16 05:05, a joeiam wrote:
> Issue:working in a file with about 6800 lines I find an error. Need
> to add two lines to one 'section'. Used +y to yank and then used
> +GP to place. Was absolutely unable to place the lines. Instead the
> 2 lines were place at the end of the document.

It looks like you're trying to yank to the system clipboard. For
that, you want

"+y

(i.e., include the double-quote before hand). The yanking sequence
as you describe it currently goes to the beginning of the next line

:help +

and then begins a yank, but leaves you in operator-pending mode as
it's expecting a motion to specify where you want to yank to.

If you've recently changed your vim, make sure that you're using one
that has been built with clipboard support. To do that, issue

:version

and look for "+clipboard" instead of "-clipboard". If you have
"-clipboard", you're likely running what some distros call "vim-tiny"
or an alternate vi such as nvi, stevie, or elvis.

If you're really trying to yank two lines into the unnamed register,
you need to specify the motion after the "y" by doing

y+

which can also be written as

yj

or

2Y

Likewise, when you go to paste, your "+GP" translates as

+ Go to the beginning of the next line
G Wait, actually go to the bottom of the file
P Paste the most recently-yanked thing before the cursor

If you want to paste from the system clipboard, again, you need to
prefix the register reference with the double-quote:

"+GP

That all said, unless you actually need the yank put on the system
clipboard, vim has a bunch of named registers if you want to keep the
content around, and defaults to the "unnamed" register. So you may
be good with just doing

yy

to yank the row (or "y+" to yank two rows, or "yap" to yank the
blank-line-delimited block), move to your destination, and

p

to paste the content. Note that those are all lowercase. There is a
"gp" command, but the (capital) "G" you're issuing is what moves you
to the end of your file.

> Used +GP a couple more times not understanding why the 2 lines were
> not placed and then I looked at the doc.I had gone from 6814 lines
> to 12 877 lines and all of the lines were the 2 yanked (with a
> blank line before and after each iteration).

I suspect something got omitted and you ended up yanking from your
current location to the end of the file, and then pasting that
content. If your cursor was at the beginning of the file to start,
that would double the size of the file.

-tim


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment