1

Can someone please tell me how to write a snippet which can emulate/simulate the behaviour of pressing the <Esc> or <Enter> etc keys from keyboard?

The following doesn't work

snippet undo "just for argument's sake"
<esc>
endsnippet

neither does this

snippet undo "i want this to result in pressing the esc key"
`!p<esc>`
endsnippet

nor this

snippet undo "simulate esc behaviour"
`!p snip.rv=<esc>`
endsnippet
3
  • The real question here is why do you want to simulate <ESC>? Do you want to get out of insert mode? I feel like you'd be better off using mappings
    – Zorzi
    Apr 20 '20 at 21:18
  • @Zorzi Actually you can think that I am trying to create a snippet for undo etc commands. There should be a way to encode <esc> etc into snippets, right?
    – Nitin
    Apr 20 '20 at 22:17
  • 1
    I don't think so, snippets are there to insert, so that's all they're good at. The can use functions (c.f. interpolation) to insert their return value, but I don't see why they would allow the encoding of <ESC>
    – Zorzi
    Apr 20 '20 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.