Applying macros to all files, macro stops processing files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Applying macros to all files, macro stops processing files

russurquhart1
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

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/1332550667.2337.1599089030863%40mail.yahoo.com.
Reply | Threaded
Open this post in threaded view
|

Re: Applying macros to all files, macro stops processing files

Tim Chase
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



--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200902191841.662e232a%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

Re: Applying macros to all files, macro stops processing files

russurquhart1



-----Original Message-----
From: Tim Chase <[hidden email]>
To: russurquhart1 via vim_use <[hidden email]>
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



If you like the results,

  :wall


--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/232596974.2044401.1599094758651%40mail.yahoo.com.
Reply | Threaded
Open this post in threaded view
|

Re: Applying macros to all files, macro stops processing files

russurquhart1
Wanted to thank Tim for this. This saved my bacon!!!

Thanks for the help!

Russ


-----Original Message-----
From: russurquhart1 via vim_use <[hidden email]>
To: [hidden email] <[hidden email]>
Sent: Wed, Sep 2, 2020 7:59 pm
Subject: Re: Applying macros to all files, macro stops processing files




-----Original Message-----
From: Tim Chase <[hidden email]>
To: russurquhart1 via vim_use <[hidden email]>
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




If you like the results,

  :wall


--
--
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 [hidden email].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_use/232596974.2044401.1599094758651%40mail.yahoo.com
.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/630676035.2256392.1599144435375%40mail.yahoo.com.