getline() does not include current edits when called from expr imap
- Dominant language
- Vim Script
- Stars
- 599
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
I'm writing an imap expr (idbrii/vim-endoscope). When testing it in Vader (gvim 7.4.52 vader ad7f1b70ebcf76de86d1991732146f2ebabe3ba4), I get different results from vim. Vader also gives a different result using the expression register and expression imap. I would expect to get the same result from all of them.
The problem appears to be that when running under vader, getline() doesn't return recent changes to the line. However, if I do `a` to break insert mode before using the expr map, getline() works correctly.
```
Before:
function! Test_GetCharBeforeCursor()
let cursor_byte = col(".") - 2
return getline(line('.'))[cursor_byte]
endf
# Stays on one side of the insert position
inoremap getline(line('.'))[col(".") - 1]
# Crosses the insert position
inoremap Test_GetCharBeforeCursor()
Given cpp (simple function with partial text):
speak("hello;
Do (FIXME: Call Test_GetCharBeforeCursor via expr map):
$i"
\
Expect cpp (quote):
speak("hello"";
Do (Workaround: Break insert then call Test_GetCharBeforeCursor via expr map):
$i"
\a
\
Expect cpp (quote):
speak("hello"";
Do (Call Test_GetCharBeforeCursor via expr register):
$i"
\=Test_GetCharBeforeCursor()\
Expect cpp (quote):
speak("hello"";
Do (One-liner that doesn't cross the insert start position):
$i"
\
Expect cpp (semi colon):
speak("hello";;
Do (Call Test_GetCharBeforeCursor via expr map without inserting a character):
$i
\
Expect cpp (letter o):
speak("helloo;
```
So the workaround (break insert with Esc) is simple, but inconvenient since I want to test repeated invocations of my imap (and each invocation does insertion).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.