Applying macros to all files, macro stops processing files

10 views
Skip to first unread message

russur...@verizon.net

unread,
Sep 2, 2020, 7:24:05 PM9/2/20
to vim...@googlegroups.com
Hi All,

Yesterday, with the groups help, I was able to apply a macro to a group of Markdown files in my site directory, using:

:args ~/site/**/inde*.md

:argdo :normal @b

:argdo :write

(@b is a macro that searches for '---', moves up two lines, and inserts a new line, 'beta: true')

I THOUGHT this would work, but i found out it didn't make it through all the files. When I looked I found that one of the files was blank. Thinking that might have caused the macro to stop at that time, I removed the file, and changed all the other files back, and tried running it again. This time, it didn't get further, but the next file it should have processed, is legit, and i can run the macro on that individual file.

Are there limitations in trying to run a macro across a bunch of files like this? Has anyone else done this?

Thanks again!

Russ

Tim Chase

unread,
Sep 2, 2020, 8:18:54 PM9/2/20
to russurquhart1 via vim_use
On 2020-09-02 23:23, russurquhart1 via vim_use wrote:
> Yesterday, with the groups help, I was able to apply a macro to a
> group of Markdown files in my site directory, using: :args
> ~/site/**/inde*.md :argdo :normal @b
> :argdo :write
> (@b is a macro that searches for '---', moves up two lines, and
> inserts a new line, 'beta: true') I THOUGHT this would work, but i
> found out it didn't make it through all the files.

In theory, this should do it

:set hidden
:argdo 1/---/-2put='beta: true'

(this assumes that the first "---" doesn't fall on the first line;
otherwise make sure you have 'wrapscan' set too and use '$/---/'
instead)

Depending on whether you insert the text above or below the line 2
above the "---", you might need to change that to "-3" instead of
"-2".

If you like the results,

:wall

> Are there limitations in trying to run a macro across a bunch of
> files like this? Has anyone else done this? Thanks again!

The biggest issue stems from a macro bombing out unexpectedly,
halting the process. As long as the macro doesn't trigger an error
condition, it should work fine. However, tracking down where the
macro fails causes more trouble than I find it worth, so I like to do
it with ex commands as above :-)

-tim



russur...@verizon.net

unread,
Sep 2, 2020, 8:59:31 PM9/2/20
to vim...@googlegroups.com
-----Original Message-----
From: Tim Chase <v...@tim.thechases.com>
To: russurquhart1 via vim_use <vim...@googlegroups.com>
Sent: Wed, Sep 2, 2020 7:18 pm
Subject: Re: Applying macros to all files, macro stops processing files



In theory, this should do it

  :set hidden
  :argdo 1/---/-2put='beta: true'

(this assumes that the first "---" doesn't fall on the first line;
otherwise make sure you have 'wrapscan' set too and use '$/---/'
instead)

Depending on whether you insert the text above or below the line 2
above the "---", you might need to change that to "-3" instead of
"-2".


IN the case of these files, the FIRST line IS a line of '---'. I was looking for the next line of '---'. Interestingly this:

 :argdo 1/---/-2put='beta: true'

seems to find the second one, and do exactly what I want. i'll try this!

Thanks again!!

Russ

russur...@verizon.net

unread,
Sep 3, 2020, 10:47:33 AM9/3/20
to vim...@googlegroups.com
Wanted to thank Tim for this. This saved my bacon!!!

Thanks for the help!

Russ


--
--
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+u...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_use/232596974.2044401.1599094758651%40mail.yahoo.com
.
Reply all
Reply to author
Forward
0 new messages