This is my path copied from the context menu Windows Explorer: "C:\Vim Python\getTime.py" and I’m trying to use The Vim Expression Register as seen in Derek Wyatt’s blog to insert output from a given Python script into a buffer.
I’ve tried all combinations I can think of slashes and quotes to get the following command to bind <c-j>dto insert the output of the script like so:
imap <c-j>d <c-r>=system("C:\Vim Python\getTime.py")<cr>
but I can’t seem to get it working without having it insert the following error:
'C:\Vim' is not recognized as an internal or external command,
operable program or batch file.
What do I need to change in order to use a filepath with spaces in it?
If you’d like to see what I’ve tried, take a look at the pastebin for a good laugh. The searches I’ve done lead me to a few different places, but none of them solved my issue, or at least, I didn’t read them correctly.
The correct solution for me was:
imap <c-j>d <c-r>=system(shellescape('C:\Vim Python\getTime.py'))<cr>
Thanks to Chiel here
Use the shellescape function of vim.
Type
:help shellescapein vim to get specific info.So changing your line to
imap <c-j>d <c-r>=system(shellescape("C:\Vim Python\getTime.py"))<cr>should do the job.