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.
I create a file
te st.txt
, open it in vim and try to save a copy namedte st.txt.backup
with:w %.backup
. This works as expected.From the same file, I try to print it to a PostScript file with
:ha > %.ps
. This time, instead ofte st.txt.ps
, I get a PostScript filete\ st.txt.ps
.If I do
:exe "ha > " . expand("%") . ".ps"
, I gette st.txt.ps
.
I do not follow the rules for using %
in command line.
Are they documented somewhere?
: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
.