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. 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 '21 at 7:37
  • Can I create aliases for some comnads like convert +append % out.png
    – Ahmad
    Jun 21 '21 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 '21 at 8:44
  • Not totally sure what you mean by an alias. If 'out.png' is static why don't you handle the parameter ordering at the shell level. You could create a wrapper script that does this and calls convert. Then use the wrapper script with netrw.
    – B Layer
    Jun 21 '21 at 8:51
  • Thank you, yes, a shell script in current directory can be called.
    – Ahmad
    Jun 21 '21 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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