vim-easymotion
vim-easymotion copied to clipboard
Requesting integration with UltiSnips - quick insertion of characters elsewhere in the line
I want to request a feature, which I am positive will be very useful. The idea is of non-local snippet for context dependent post fixing of ),}, etc.
I am a user of both UltiSnips and EasyMotion plugin, so I came up with an idea of how some tweaks with the latter could provide this feature, but probably it won't belong there. So I want to request UltiSnips to consider it too. An integration might be a good idea.
I am not a pro developer, but I will also provide an incomplete implementation.
Idea and motivation
Often when writing LaTeX, equations are very long. Take for example
$$ \alpha^2 = \beta^2 + \gamma^2 - \frac{1}{\sqrt{a^2 +b^2}} .$$
Suppose that while writing this equation, I realize that "oh, the \gamma^2 - \text{frac}.. term needs be in brackets, and then be raised to power 2, i.e. the correct equation should be
$$ \alpha^2 = \beta^2 + \left( \gamma^2 - \frac{1}{\sqrt{a^2+b^2}} \right)^2 .$$
While on paper a quick (non-local) insertion of a single character takes no time, on computer you have to move the cursor, insert and then return.
The situation is same if you want to insert a $[, \{, \int, \sum$, etc.
Such a non-local (but still within the line) operation cannot be solved by simple post fixing because of it being highly dependent on the context.
However, with easymotion it can be made much faster.
Concept
Imagine a snippet )) which can trigger the easymotion command easymotion-Fl, with trigger text ' ', i.e. a space.
This operation will highlight all the spaces in the current line with red letters like a, b, c,... By choosing the letter for desired position, ( can be inserted at the location.
When done right, this will take 3 keystrokes in total: 2 for the snippet, 1 for the position. In the first two we give information of "what to do" and in third, "where to do".
My incomplete implementation
I tried do use vimscript for this - but couldn't achieve this 3 stroke functionality. I used the (undocumented) function
inoremap )) <space>)<Esc>:call EasyMotion#User(' ', 1, 1, 1)<CR>
which after inserting a ) asks for the space I wanna jump to, but it ends after jumping. Upon reaching there, I do r(% to return where I was - this part is what needs to be automated.
Note that this automation could have been possible if EasyMotion provided an autocommand trigger for having jumped to target, which it doesn't.
Where UltiSnips enters
I think this is a snippet rather than a motion, so if the integration is simple, I would love UltiSnips to have this feature.
Any thoughts whould be appreciated!