Trying to apply macro to all files under a folder

9 views
Skip to first unread message

russur...@verizon.net

unread,
Aug 31, 2020, 6:57:18 PM8/31/20
to vim...@googlegroups.com
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




Tim Chase

unread,
Aug 31, 2020, 7:14:47 PM8/31/20
to russurquhart1 via vim_use
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



russur...@verizon.net

unread,
Aug 31, 2020, 7:37:01 PM8/31/20
to v...@tim.thechases.com, vim...@googlegroups.com
Hi TIm,


-----Original Message-----
From: Tim Chase <v...@tim.thechases.com>
To: russurquhart1 via vim_use <vim...@googlegroups.com>
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

Tim Chase

unread,
Aug 31, 2020, 7:55:14 PM8/31/20
to russur...@verizon.net, vim...@googlegroups.com
On 2020-08-31 23:36, russur...@verizon.net 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


russur...@verizon.net

unread,
Aug 31, 2020, 8:18:38 PM8/31/20
to vim...@googlegroups.com
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200831185503.4c7e997e%40bigbox.attlocal.net.

Reply all
Reply to author
Forward
0 new messages