Thursday, June 20, 2013

Re: append to non-blank lines in a selection

On 2013-06-20, Chris Lott wrote:
> Given a text:
>
> line1 has stuff
> so does line 2
>
> line 4 has more stuff
> and line 5
> and so on
>
> I would like to select the text block and append a word to each
> non-blank line. I can use a block selection and `A` to add to all
> selected lines, but not sure how to only apply to lines that have
> text.

I don't think there is a way to qualify an operation like A on a
visually-selected region like that. However, you can so qualify a
:substitute command. Select the text block and type

:g/./s/$/word/

When you type the colon, Vim will automatically insert the names of
the marks for the beginning and end of the selected block, so you
will see this on the command line:

:'<,'>g/./s/$/word/

Then hit Enter.

The :g (:global) command followed by the pattern . specifies that
the :s (:substitute) command is to be executed only on those lines
containing at least one character. The :substitute command
substitutes the end of the line ($) with "word".

See

:help :g
:help :s
:help /$

Regards,
Gary

--
--
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/groups/opt_out.

No comments:

Post a Comment