UltiSnips and insert mode mappings

Asked by Thiago A.

Hi,

Congratulations for UltiSnips. I've got some simple insert mode mappings that don't work when I'm typing in the placeholders. For example:

inoremap <expr> ' g:InsertPair("'")
inoremap <expr> " g:InsertPair('"')

function! g:InsertPair(char)
    let next_char = strpart(getline('.'), col('.') - 1, 1)
    let char_is_rightside = next_char == a:char
    if char_is_rightside
        return "\<Right>"
    else
        return a:char . a:char . "\<Left>"
    endif
endfunction

These mappings do not work when I'm expanding a snippet. Is there any fix for it?

Thanks and keep up the good work.

- Thiago

Question information

Language:
English Edit question
Status:
Answered
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
SirVer (sirver) said :
#1

Hi. Short answer: no, not likely.

We essentially have to guess what has been entered each time the cursor moves by examing the current and the last few lines and comparing them to what we saw earlier. We are easily fooled whenever one of Vims magic is happening. When UltiSnips is expanding a snippet, it takes control over the are of text the snippet spans and overwrites it with each keystroke - there is literally no way around this. So, UltiSnips will not pick up on your insert mode mapping and therefore it is not properly expanded for you.

The only way around this would be to get deeper control into vims text handling pipeline. This is not avaiable for python though and I doubt it is available for VimL scripts.

So sorry, out of luck here :/.

Can you help with this problem?

Provide an answer of your own, or ask Thiago A. for more information if necessary.

To post a message you must log in.