Deleting all but selected on a line

1 view
Skip to first unread message

Hansen, Mike

unread,
Dec 3, 2008, 12:06:10 PM12/3/08
to v...@vim.org
I'm cleaning up a Perl Template Toolkit template, and I was wondering
how would you select some text on a line and delete anything else on
that line that isn't selected.

<input type="text" class="yadda_yadda" value="[% something_important &]" />

If I visually selected [% something_important %], is there some VIM
magic that I could delete everything else on the line?

Mike

Hansen, Mike

unread,
Dec 3, 2008, 12:40:47 PM12/3/08
to vim...@googlegroups.com

I'll answer my own question. I solved it by recording a macro, but I'm interested in other solutions.

Mike

fritzophrenic

unread,
Dec 3, 2008, 12:45:36 PM12/3/08
to vim_use
I'd personally just yank it, delete the whole line, and put it the
yanked text back:

y0Dp

or

ycc<esc>p

If you do this often, maybe make a vmap to do it for you with one
keystroke.

Marc Weber

unread,
Dec 3, 2008, 12:48:59 PM12/3/08
to vim...@googlegroups.com
> I'll answer my own question. I solved it by recording a macro, but I'm interested in other solutions.
I usually do
y0PlD

Marc

Marc Weber

unread,
Dec 3, 2008, 1:12:04 PM12/3/08
to vim...@googlegroups.com
> y0Dp
Don't forget that D will override your yanked text..

Hansen, Mike

unread,
Dec 3, 2008, 2:58:18 PM12/3/08
to vim...@googlegroups.com

Thanks. That does the trick.

Mike

fritzophrenic

unread,
Dec 4, 2008, 9:06:04 AM12/4/08
to vim_use


On Dec 3, 12:12 pm, Marc Weber <marco-owe...@gmx.de> wrote:
> > y0Dp
>
> Don't forget that D will override your yanked text..

Whoops, that's right.

Make that y0D"0p

And the same for the cc<esc> option.

I like your method better...much shorter.

Chris Suter

unread,
Dec 6, 2008, 4:58:21 PM12/6/08
to vim...@googlegroups.com
if you have the text selected in visual mode already, you could simply do dVP. this will delete the selected text, putting it in the " register, then select the whole line, and replace it with the contents of the " register.
--
Christopher Suter
Reply all
Reply to author
Forward
0 new messages