Saturday, April 2, 2016

Re: Need help with macro

On 2016-04-02 09:34, Dmitry Teslenko wrote:
> I have this block of text:
>
> START
> aaaa
> bbb
> cccc
> END
>
> I try to record a macro that perform substitutions between START
> and END. Say, I need to replace aaaa with ee and cccc with ff.
> Cursor is at START. I do visual selection and then search
> replace :<,>s My problem is macro execution terminates on search
> item not found.

The immediate solution is to use the /e flag for :s to ignore errors
when the pattern isn't found. That said, vi/vim excels at doing this
sort of manipulation:

:g/START/.+1,/END/-1s/aaaa/ee/e|.+1,/END/-1s/cccc/ff/e

or, making use of defaults for line incrementing/decrementing:

:g/START/+,/END/-s/aaaa/ee/e|+,/END/-s/cccc/ff/e

will do your entire file in one pass without macros.

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