Trying to apply macro to all files under a folder

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

Trying to apply macro to all files under a folder

russurquhart1
I found a ref to this and some commands that should work, but wont for me.

In my site directory, are other directories and files. I have a macro that I created, @b that i want to run recursively on all files named index.md in all the folders in site.

I had initially set CWD to the site directory.

In vim i did:

: args inde*.md

(Thinking this should put all the index.md files into the arg list. That didn't work, it only found the one index.md file in site.)

My next step would have been:

:argdo :normal @b

(That works for the one file it found.)

Then i would save my files:

:argdo :write

Should this work? How can I get this to work. All examples I've found describe this, but it doesn't want to work for me. 

Any help is greatly appreciated!

Thanks,

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/349437253.960842.1598914623663%40mail.yahoo.com.
Reply | Threaded
Open this post in threaded view
|

Re: Trying to apply macro to all files under a folder

Tim Chase
On 2020-08-31 22:57, russurquhart1 via vim_use wrote:
> My next step would have been: :argdo :normal @b

I *think* you need to apply the :normal to the whole file unless the
macro itself does everything in one invocation.

If it only does one line and you need it to do the whole file, you
might try

  :argdo :%normal @b

If it's a recursive macro, its fail-at-the-end condition might also
cause issues triggering the :argdo to stop.

  :help :argdo

  When an error is detected on one file, further files in the
  argument list will not be visited.

If I had to point my finger at my first suspect as to why your
attempt isn't working the way you want, this is it.

> Then i would save my files:
> :argdo :write
> Should this work?

this should work as long as 'hidden' is set.  It used to default to
off, but I think that recent changes in the defalts flipped this.
Regardless, you want to make sure you

  :set hidden

first just to know that it's set.  This lets you leave modified
buffers.  Once you've made the changes, you can then do

  :argdo write

or

  :argdo update

to only write those files that have been modified.

-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/20200831181432.16132c14%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

Re: Trying to apply macro to all files under a folder

russurquhart1
Hi TIm,


-----Original Message-----
From: Tim Chase <[hidden email]>
To: russurquhart1 via vim_use <[hidden email]>
Sent: Mon, Aug 31, 2020 6:14 pm
Subject: Re: Trying to apply macro to all files under a folder

On 2020-08-31 22:57, russurquhart1 via vim_use wrote:
> My next step would have been: :argdo :normal @b

I *think* you need to apply the :normal to the whole file unless the
macro itself does everything in one invocation.


The @b macro only adds a single line of text.



If I had to point my finger at my first suspect as to why your
attempt isn't working the way you want, this is it.

> Then i would save my files:
> :argdo :write
> Should this work?

this should work as long as 'hidden' is set.  It used to default to
off, but I think that recent changes in the defalts flipped this.
Regardless, you want to make sure you

  :set hidden

I'll check this!

The only other wrinkle is that I am working on a git local branch. I haven't had any issues using Vim in this situation.

When you set the arg list, where does it start? from your current working directory?

(Just tried copying the Site directory from the git branch to a directory, and then trying the same commands, still the same thing. Just gets the first file in site and does not check the other directories in site.)

Thanks

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/155979643.974477.1598917007276%40mail.yahoo.com.
Reply | Threaded
Open this post in threaded view
|

Re: Trying to apply macro to all files under a folder

Tim Chase
On 2020-08-31 23:36, [hidden email] wrote:
> I *think* you need to apply the :normal to the whole file unless the
> macro itself does everything in one invocation.
>
> The @b macro only adds a single line of text.

If it's a whole line, you might have better luck with the :put
command such as

  :argdo 0put='Line of text to put at the top'

> The only other wrinkle is that I am working on a git local branch.

That shouldn't impact anything.  I regularly work on local git
branches without issue.

> When you set the arg list, where does it start? from your current
> working directory?

It depends a bit on how you populate it and how your OS expands
globs, I suspect.  Once you've populated it with

  :args **/inde*.md

or whatever, you can check/display the arg-list by just issuing

  :args

without additional parameters.  I think your original glob didn't
recurse into subdirectories, so you might also need to prepend "**/"
to search into subdirectories

  :help starstar

-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/20200831185503.4c7e997e%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

Re: Trying to apply macro to all files under a folder

russurquhart1
You are correct!


-----Original Message-----


> When you set the arg list, where does it start? from your current
> working directory?

It depends a bit on how you populate it and how your OS expands
globs, I suspect.  Once you've populated it with

  :args **/inde*.md

or whatever, you can check/display the arg-list by just issuing

  :args

without additional parameters.  I think your original glob didn't
recurse into subdirectories, so you might also need to prepend "**/"
to search into subdirectories

  :help starstar


I found this later, and THIS was the issue/answer! starstar gave me the correct argslist!

Thanks!!

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+[hidden email]
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200831185503.4c7e997e%40bigbox.attlocal.net.

--
--
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/1587143643.999413.1598919507405%40mail.yahoo.com.