Monday, February 28, 2011

Re: Editing contents of a register?

On 02/28/2011 07:49 PM, Rostyslaw Lewyckyj wrote:
> Suppose that I have a collection of editing commands such as
> %g/pattern_a/
> %g/pattern_b/
> %g/pattern_c/
> ........................
> that find and list all the lines of a file that satisfy some patterns.
> After I visually inspect a given list of lines, I may want to delete them.
>
> I have thought to do this as follows:
> -- yank a list command into a register "ayy
> -- execute the command :@a"
> -- inspect the lines as they are listed
>
> Then if I'd now like to delete this set of lines, I'd like to append a d
> to the contents of register a changing it from a list to a delete command,
> and execute the command.
>
> So how do I _easily_ modify, edit, the contents of a register?
>
> I'd like something simpler than loading a list command into the clipboard
> via highlighting and ^C followed by :^V and if choosing to delete
> then :^Vd ???

I've done something like this in the past where I've modified my
buffer such as you have with

:%s/.*/:&d

which leaves the buffer looking like

:%g/pattern_a/d
:%g/pattern_b/d
...

with leading colons and trailing "d" commands.

You can then yank that entire buffer's contents and execute it as
a macro:

:%y
@"

or if you want to name it,

:%ya
@a

You can also modify registers by using the "@" notation:

:let @a='hello' . @a . 'world'

-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

No comments: