0

I have been trying the https://github.com/ngemily/vim-vp4 plugin for integrating Perforce version control commands into Vim.

The Vp4Diff command fails for me. I tracked it down to a step where a system(cmd) function was being called when cmd = "p4 fstat-T headrev <filename>#have".

The problem is actually not caused by Perforce. I find that any cmd containing a # character will fail.

:call system('touch #this')

...but I get an error:

E484: Can't open file /tmp/vx0yoZZ/1

I'm using Vim 8.2.1001. This happens for both tcsh shell and bash. It also happens when running vim --clean.

I'm disapointed the error message wasn't "U Can't Touch #This"

2
  • 1
    # indicates a comment in the shell (where that is running). You can quote it... system("touch '#this'") ...which will prevent its interpretation as a comment char.
    – B Layer
    Aug 25, 2021 at 21:09
  • 1
    ...escaping it should work, too, FYI ... system('touch \#this').
    – B Layer
    Aug 25, 2021 at 21:15

1 Answer 1

0

Escaping the # is necessary for the shell to not consider it a comment.

That can be done with the escape() function:

let cmd = 'touch #this'
call system(escape(cmd, '#'))

The shellescape() function does not work here because a pair of single quotes would surround both words together, as if 'touch \#this' was a single Linux command.

1
  • Well, it'll work if you do system('touch ' . shellescape('#this')) which is a perfectly reasonable approach although fnameescape('#this') is probably a better choice.
    – B Layer
    Aug 26, 2021 at 4:36

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.