You definitely need the backslash version
\<Left>. Is use of
py3eval necessary? Unless you need to translate data structures from Python to Vim or something it would be better to return a straight string. You need to make sure the string
:GrepperAck ''\<Left> is passed literally to the command line. Then it will be processed as an expression due to
I don't have a Python installation but I can demonstrate the fundamental workings without it. Given...
return ":GrepperAck ''\<Left>"
And this mapping...
nnoremap <expr> <leader>f Foo()
Then when I enter leader key and f this is what I'll see on the command line..
...and the cursor will be inside the quotes.
If you must use
py3eval then one thing you might try is to wrap that in a
string() function call.
nnoremap <expr> <leader>f string(py3eval(..))
Update: In retrospect the reason
\<Left> doesn't work is almost certainly because the parsing of the mapping occurs in a certain order, i.e. the phase that substitutes actual keys for
<xxx> tokens occurs before any external programs are executed. I haven't confirmed this by looking at the Vim source code or anything but as a veteran software developer I can tell you that it's a solid theory. It wouldn't make much sense for the parser to have multiple passes with
<xxx> resolution nor, generally speaking, to make such a pass over external (non-Vim originated) runtime data.
Can anything be done? Well, I thought that substituting the actual key code would do the trick....
return ":GrepperAck ''<C-V><Left>"
That means rather than type
\<Left> you actually enter Ctrl+V followed by ← (left arrow key). (For me the combo comes out looking like
^[OD.) Unfortunately, I'm getting an error:
Not an editor command: GrepperAck ''. But I know I'm on the right track because if I replace ← with Ctrl+H (commonly the same function as the backspace key) then the cursor is actually moved on the resulting GrepperAck command line (erasing the last
' as expected).
So why isn't the left arrow key code working? Dunno. It might be that we can substitute something else in the terminal codes but that's a stretch and getting into possibly non-portable behavior. I'll play around with that for a bit but unfortunately, unless your system behaves differently than mine (try it out) I believe the ultimate answer to your question is "this is not possible".