1

I have a noremap that sends the current full file path to an interpreter.

The problem is that on windows the \ need to be / -- so when i pass expand("%:p") an error is thrown.

I have figured how to do this with a string in the editing frame in vim using :s@\\@/@g, however, i cannot figure out how to apply the substitute command to the string before sending it from vim to the interpreter.

Is this possible?

1 Answer 1

3

There's a substitute() function that works like :s: Just use substitute(expand("%:p"), '\\', '/', 'g'). However, for this particular character swap, the simpler tr() will suffice: tr(expand("%:p"), '\', '/').

Actually, a simple substitution can actually be combined with expand() (thanks Peter Rincker for the comment!), through a rather obscure feature of filename-modifiers: expand('%:p:gs?\\?/?').

Also, have a look at :set shellslash; it can globally translate backslashes into forward slashes on Windows.

2
  • +1 / accepted ... thanks (of course it's possible ... this is vim :)
    – ricardo
    Aug 6, 2013 at 7:48
  • 3
    You can to the expand and substitute in one command: expand('%:p:gs?\\?/?'). See :h filename-modifiers for more information. Aug 6, 2013 at 13:39

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.