Tuesday, February 17, 2015

Re: vim: least key stroke to replace a word

On 2015-02-17 10:57, Arun wrote:
> On Tue, Feb 17, 2015 at 10:18 AM, ping song
> <songpingemail@gmail.com> wrote:
>
> > experts:
> > I know this looks stupid and simple, but I don't know the answer
> > right now.
> >
> > say I want to replace a word :
> >
> > from:
> >
> > abc 456
> >
> > to:
> > 123456
> >
> > what I did is:
> > 1. put my cursor in a, then cw123<esc>x , 7 strokes
> > 2. put my cursor in b, then caw123<esc>, 7strokes
> > 3. put my cursor in a, then dwi123<esc>, 7 strokes
> >
> > it looks cw and dw behaves non-consistently, which I know is by
> > the design.
> >
> > I'm editing an old doc full of typos and spelling errors, etc,
> > and I need to do this quite often, does anyone knows of a
> > least-strokes-method (to protect my fingers) ?
>
>
> How about one or more of the following approaches:
> 1. :s/<old>/<new>/g { or s/<old>/<new>/gc for interactive }
> 2. Do caw123<esc> and repeat further occurences with "." (dot)
> 3. Recording multiple common occurrences into multiple registers
> (say a,b,c)
> and apply using (@a, @b, @c) {See :h recording}
> For eg: qa/abc 456<cr>caw123<esc>q { You have now recorded
> abc to 123 transformation
> into register a. Apply further occurences using @a (further
> hits can use @@) }. Of course,
> if you do not want the search to be part of the macro, you
> can drop it.

Arun give several good suggestions. Also, if done frequently enough,
you can just create a mapping like

:nnoremap <space> caw

allowing you to simply hit <space> on a word to change it, reducing
your overhead to 2 keys, start and stop.

-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

---
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/d/optout.

No comments:

Post a Comment