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?

4

1 回答 1

3

有一个substitute()功能类似于:s:只需使用substitute(expand("%:p"), '\\', '/', 'g'). 但是,对于这种特殊的字符交换,更简单的tr()就足够了:tr(expand("%:p"), '\', '/').

实际上,一个简单的替换实际上可以expand()通过 filename-modifiers: 的一个相当模糊的特性与(感谢 Peter Rincker 的评论!)结合使用expand('%:p:gs?\\?/?')

另外,看看:set shellslash;它可以在 Windows 上将反斜杠全局转换为正斜杠。

于 2013-08-06T06:40:36.793 回答