SirVer / ultisnips

UltiSnips - The ultimate snippet solution for Vim. Send pull requests to SirVer/ultisnips!
GNU General Public License v3.0
7.5k stars 688 forks source link

Partial imap commands clear default placeholders #1431

Closed xsrvmy closed 2 years ago

xsrvmy commented 2 years ago

Using an imap keymapping will remove the placeholder when the first key is pressed.

Expected behavior: Placeholder is cleared only after imap executes, and only if the command types text in insert mode.

Actual behavior: Placeholder is cleared on first keystroke.

Steps to reproduce First use case: Consider a snippet like this: while (${1:true}) {$0}. If I have jk mapped to escape, then hitting jk to escape will clear the true inside the snippets, so only escape works here.

Second use case (my use case): Consider this snippet: $${1: }$, which enters math mode in latex. Here the default space prevents the lexer from interpreting $$ as entering display math, which would mess up syntax highlighting and conceal. If I immediately type `a after this snippet to enter an alpha, the first backtick clears the placeholder which negates the benefit of the extra space. To be clear, the placeholder should still be cleared in this case, but only because the result of the imap is to input characters.

Note: `a is a vimtex-defined imap from `a to \alpha (or in my case, a unicode alpha).

imap and inoremap doesn't make a difference.


SirVer commented 2 years ago

So, the selection of a tabstop moves Vim into select-mode (see help select-mode) which is neither insert nor visual mode and uses different keymaps, so your imap is not defined in that case. You might be able to make your imaps also smap or xmaps, but I doubt that this is really feasible in your case. I do not have a good suggestion on how to handle your use case, it seems a weird combination of limitations of UltiSnips + Limitations of Vim + Limitations of vimtex combined.....

SirVer commented 2 years ago

@xsrvmy Did you figure something out for this?

xsrvmy commented 2 years ago

I switched to using \(\) in vimtex so this isn't a problem anymore.