Thursday, October 17, 2013

Re: Save a selection


On Oct 17, 2013 5:53 PM, "Ben Fritz" <fritzophrenic@gmail.com> wrote:
>
> On Thursday, October 17, 2013 7:48:25 AM UTC-5, shawn wilson wrote:
> > My problem is that I often select a portion of code and do multiple
> >
> > :%s/foo/bar/g (or /gc - whatever) after, the code selection disappears
> >
> > and I need to select that area again if I want to replace something
> >
> > else. I can remember line numbers or put a mark at the end. Is there a
> >
> > way to save the selected area or a better way to do this?
>
> Everybody suggested gv to reselect the area, I'm surprised nobody mentioned that you don't NEED to reselect the visual area, nor do you need to manually set marks.
>
> Every time you create a visual selection, Vim automatically sets the '< and '> marks.
>
> So to run several sequential commands on the same visual selection:
>
> {make visual selection}
> :'<,'>FirstCommand
> :'<,'>SecondCommand
> :'<,'>ThirdCommand
> :'<,'>Etc
>
> Note that for FirstCommand, as soon as you press :, the marks '<,'> are inserted for you by Vim. The others you can enter manually or use command-line history to recall a previous command you can edit.

One can use :*Command as a shortcut for :'<,'>Command. If this does not work check out 'cpoptions' value, it should not contain star (:h cpo-star).

> --
> --
> 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.

--
--
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: