Normal mode commands in snippets

Asked by Duncan de Wet

If I type

    :normal kyypVr-jdd

in Vim, it does the same as typing kyypVr-jdd in normal mode (it writes ------ to length of the above line, useful for ASCII doc).

However, I can't get it to work in a UltiSnips snippet; I've tried many variations of

    snippet --
    `!v normal kyypVr-jdd`
    endsnippet

but just can't get it to work.

Is this supposed to work? If not it would be a nice feature to have. However I can't see why it wouldn't work as it is Vimscript after all.

Question information

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

Unfortunately Vim delays any normal commands until the currently running function is done, i.e. after the snippet completion is done or the move command is done. Therefore this will never behave as you expect it too and there is very little that can be done there I think.

However, if you use python in your snippet, you can access vim.current.buffer directly and copy the lines over that you are interested in - if this was not just an example and you are actually interested in this normal command. Also see the .rst snippets that come with ultisnips and their "sec" snippet in particular. It does exactly what you want to do in this example.

Revision history for this message
Duncan de Wet (duncandewet) said :
#2

Thanks SirVer, that solved my question.