On 2013-10-17 06:53, Ben Fritz 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.
I started a similar reply but Ben beat me to the <send> button.
It's also helpful to know that you can also use "*" to mean the same
visually selected range, so you can
1) highlight some lines
2) press ":" which autopopulates the range '<,'>
3) add your first command and execute it
4) type ":*Command2" and execute it to reuse the same '<,'> range
And I'm all about the lazy :-)
-tim
PS: this only works if "*" isn't in 'cpoptions' according to ":help
cpo-star", though that should be the default shown at ":help 'cpo'"
--
--
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.
Thursday, October 17, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment