Vim: "Can't open file /tmp/[random string]/[integer]"
Back to Vim!
Ran into this today while using my Vim function that sends the current reading journal entry (a single line of text) to a script that creates a Books! entry on my website.
The exact error in my case:
Error detected while processing function NewBook: line 1: E282: Cannot read from "/tmp/vWLQU2E/2" Press ENTER or type command to continue
Turns out, it was pretty easy to figure out what had gone wrong. The line of text
from my reading journal is sent to the script with the following system() call:
silent let foo = system("new-book '" . getline(".") . "'")
The single quotes (') are intended to ensure the whole line gets sent as the
first parameter to the script called new-book.
But the book title giving me trouble? Howl’s Moving Castle. Yup, single quote.
I tested the string with Vim’s shellescape() function:
:echo shellescape("Howl's Moving Castle")
'Howl'\''s Moving Castle'
Looks good, so here’s the fix:
silent let foo = system("new-book " . shellescape(getline(".")))
(Note that I removed the now-redundant single quotes from around the escaped string!)
Vim’s error message is very misleading and I’m not sure why my attempt to catch an error condition in my Vim function isn’t working. But at least my shortcut works again, so I’m done with this for now.