I cannot figure out the general rules for using % to substitute the current file name/path into a command line mode command.

Here are examples.

  1. I create a file te st.txt, open it in vim and try to save a copy named te st.txt.backup with :w %.backup. This works as expected.

  2. From the same file, I try to print it to a PostScript file with :ha > %.ps. This time, instead of te st.txt.ps, I get a PostScript file te\ st.txt.ps.

  3. If I do :exe "ha > " . expand("%") . ".ps", I get te st.txt.ps.

I do not follow the rules for using % in command line. Are they documented somewhere?

  • 1
    I think the problem is related to the :hardcopy command, as I can't see this behaviour with other commands. Perhaps it is a bug? If you use % after a :! command, you should note that the :S modifier can be useful to automatically escape e.g. spaces in paths. E.g. :!sort -u %:S. May 5, 2017 at 13:02
  • 1
    I created an issue report about this.
    – Alexey
    May 6, 2017 at 11:59

1 Answer 1


This was a bug, it must be fixed with patch 8.0.0615.

Your Answer

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

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