ultisnips icon indicating copy to clipboard operation
ultisnips copied to clipboard

Option to finish snippet expansion in command mode

Open roelvandergoot opened this issue 3 years ago • 5 comments

This is a feature request. Would it be possible to add a snippet option to finish the snippet in command mode after pressing the jump-forward-trigger key the final time?

roelvandergoot avatar Oct 12 '21 16:10 roelvandergoot

This is conceptually possible, but was never requested before in the last 14 years of development, hence I am careful with accepting this feature request. Could you outline a use case?

SirVer avatar Oct 13 '21 12:10 SirVer

Hi all,

Thank you for considering my request.

I will explain my use case. I developed a domain specific language to specify resource/object/data models by giving meaning to certain keywords in YAML. I created a couple of snippets that create/add relationships between resources. These snippets insert a couple of lines into the YAML file. The main use case is to add a relationship to an existing YAML file. At the end of the data insertion, I tend to navigate to another party of the file, hence I would like to be in the vim command mode.

Let me know if you have additional questions.

Thank you for developing and maintaining Ultisnips!

Cheers :), Roel.

On Wed., Oct. 13, 2021, 06:39 Holger Rapp, @.***> wrote:

This is conceptually possible, but was never requested before in the last 14 years of development, hence I am careful with accepting this feature request. Could you outline a use case?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SirVer/ultisnips/issues/1399#issuecomment-942262005, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKRYJRI3NUPK6TTUGE7BGTTUGV4YTANCNFSM5F3BHLMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

roelvandergoot avatar Oct 13 '21 16:10 roelvandergoot

I think a snippet option is feasible that ends insert mode once the snippet exits. I am not sure which mechanism can be reliably used to exit insert mode, but in the worst case an escape could be send.

SirVer avatar Oct 15 '21 13:10 SirVer

look at :help :stopinsert I think it's the most reliable way of doing it

hl037 avatar Nov 04 '21 09:11 hl037

This request could be done with a post_jump action, checking if we are at the end of the snippet with the value of snip.tabstop, and a vim timer that sends an <Esc> via feedkeys:

For example, to exit insert mode at the last tabstop,

post_jump "if not snip.tabstop: vim.eval('timer_start(0,{-> feedkeys("\<Esc>")})')"
snippet bbbb "test" b
bb ${1:def} ghi $0
endsnippet

A timer is needed here, as snippet_manager._jump() implicitly does a :startinsert through vim_helper.feedkeys(). Thus, to prevent timing conflicts, timer_start(0,{-> feedkeys("\<Esc>")}) will perform <Esc> after :startinsert.

BertrandSim avatar Sep 29 '22 08:09 BertrandSim