Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.

vifm: run command on each selected file individually

0 votes
asked Oct 13 in vifm by petRUShka_sch2

I want to for loop analog for vifm.

When I don't select any file I can type :!echo %f and I see output of echo with current file name as argument.

When I select several files :!echo %f yields output of echo with all selected filenames joined with spaces as argument.

What if I want to apply any program (e.g. echo) to each selected file? So

echo file1
echo file2
echo file3
...

instead of

echo file1 file2 file3

What options do I have?

P.S. I want analog of bash code like this:

for f in file1 file2 file3; do
  echo $f;
done

1 Answer

0 votes
answered Oct 15 by xaizek

There is no for-each mechanism, so you need to write the loop explicitly like in:

:%!for i in %f; do echo "$i"; done

Maybe define a command like

command! foreach for f in %f; do %a; done

to shorten what you have to type down to

%foreach echo "$f"
If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here is acceptable, but this is not a perfect place for them.
...