Saturday, July 10, 2021

Re: Seach and follow with keystrokes or a macro


   > Is there anyway to search and replace in a single colon command?

Yes, use `:normal`, possibly in combination with `:global`.  Record your key presses (`    9lv10l~0`) into the macro `q`.  Then, execute:

    :%norm! @q

To execute the macro on all the lines in the file.

Or:

    :*norm! @q

To execute the macro on all the lines which were in the last visual selection.

Or:

    :g/^keyword:/norm! @q

To execute the macro on all the line starting with the text `keyword:`.


On Saturday, July 10, 2021 at 3:24:12 PM UTC+2 gua.ch...@gmail.com wrote:
Hi,

I have been using vim for years, I usually use @ macros. I have a question hard to explain. Assuming I have a text file ...

keyword: toggle CASE Retentive Case
keyword: TOGGLE case Retentive Case
keyword: togGLE CASE Retentive Case
...

And I want to toggle the case of some letters after ^keyword:.
Things I usually do is ...
/^keyword
then do the following keystrokes ...
9lv10l~0
And for the rest of file I can simply do ...
n.
to find the next match (n), and repeat the keystrokes (.)

Certainly, I can assign 9lv10l~0 to a macro. But what if I have 1,000+ lines like this, I would never want to use the macro for every line containing "^keyword". Is there anyway to search and replace in a single colon command? Like ...

:%s/^keyword/do_keystrokes/g
or
:%s/^keyword/do_a_macro/g

Thanks in advance,

--
Gua Chung Lim

Nothing ever exists entirely alone without dualities.

--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/bb67ddcd-3feb-4504-9662-a79530ce0837n%40googlegroups.com.

No comments: