2

I have an exe program that checks for certain errors in a text file.

I want to create a shortcut (like \+M) to run that exe file against the text file.

My exe file's path is C:\Users\xyz\Documents\Checker\manager.exe, the text file's path is C:\Users\xyz\Desktop\mytextfile.txt.

The manager just needs the following command:

check [full filepath to the text file

Here is what I have tried in the VIM plugin file.

function! ExecuteManagerCheck(file)
    execute ':!start cmd /k "C:\Users\xyz\Documents\checker\manager check " g:file'
endfunction

nmap <leader>m :call ExecuteManagerCheck(expand('%:p')) <cr>

Can someone please help me get the full file path to the current text file open in Vim?

  • 2
    That should probably be a:file and not g:file – D. Ben Knoble Jun 15 '18 at 20:54
  • 1
    Your expand('%:p') should work, according to eval.txt, but the quotemarks in "C:\...\manager check " don't make sense. Do you see any error messages when you try to run the plugin? – JigglyNaga Sep 13 '18 at 15:44
0

The problem is with the quotes around your :execute command. You want to close the single quote and then concatenate the a:file argument there. Then close the double quotes for the cmd /k execution.

Oh and like @D.BenKnoble mentioned in the comments, it's a:file (to refer to the argument passed to the function) rather than g:file (which refers to a global variable by that name.)

It's likely you might also need escaping, for this to still work if your filename contains special characters. I'm not too familiar with Windows to be able to tell you which one is right for you there, please experiment with escape() and friends.

function! ExecuteManagerCheck(file)
    execute ':!start cmd /k "C:\Users\xyz\Documents\checker\manager check '.a:file.'"'
endfunction

nmap <leader>m :call ExecuteManagerCheck(expand('%:p'))<cr>

(And for escaping, I think escape(a:file, ' "\') might be the one you need...)

  • 1
    Using double quotes together with a backslash won't work. You need to escape the backslashes in this case. – Christian Brabandt Sep 6 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy