I want to apply a shell command on two selected files, my command is:

convert +append image1.png image2.png output.png

How can I do that for two selected images in netrw? However, to make the process easier I wrote a shell function named append which takes two image and generates and output name for them and applies convert on them. Now, how can I use my shell function on the selected files?

1 Answer 1

  1. Mark the files using one of ways detailed here. (E.g. type mf with the cursor over a filename.)

  2. Type mx

  3. At the prompt enter your shell command.

    • If you want to specify where marked files should be inserted in the command line indicate this with a %.
    • Alternatively, don't add a % and marked files will follow the command after a space.
  4. Hit Enter.

The command should then be run on each file in turn.

The example found in the relevant section of netrw docs

(mark files)
Enter command: cat

The result is a series of shell commands:

cat 'file1'
cat 'file2'

If instead you want the command run once on all the files at one time use mX instead of mx.

The documentation example for that one, showing creation of a tarball:

(mark files)
Enter command: tar cf mynewtarball.tar

The command that will be run with this example:

tar cf mynewtarball.tar 'file1' 'file2' ...
  • Thanks, how about applying a shell function I defined myself?
    – Ahmad
    Jun 21, 2021 at 7:37
  • Can I create aliases for some comnads like convert +append % out.png
    – Ahmad
    Jun 21, 2021 at 7:43
  • You'll either need to make sure your PATH includes your script before you start Vim or you should specify it's full path at the prompt that follows mx/mX. (I haven't tried this but I'm pretty confident it'll work. Let me know if you have issues.)
    – B Layer
    Jun 21, 2021 at 8:44
  • Thank you, yes, a shell script in current directory can be called.
    – Ahmad
    Jun 21, 2021 at 9:37
  • 1
    @CervEd It works for me. For example, I put the cursor on "./", do mf, then mx, type ls then Enter and it shows the listing for that directory.
    – B Layer
    Oct 4, 2022 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.