Ultisnips: Enter replace mode at tab stop.

Created on 26 Jan 2018  路  4Comments  路  Source: SirVer/ultisnips

Is there a way to enter into Replace mode at a tab stop?

I have a comment block snippet:

snippet // "comment block" b
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// ${0}  <---- want to add bits here while keeping this aligned right ---->   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
endsnippet

Tried the following with no success:

${0}`!v execute("normal! R")`

As well as:

```vim
post_expand "vim.command(\"exe ':normal R'\")"
snippet // "comment block" bm
////////////////////////////////////////////////////////////////////////////////
// //
// ${0} //
// //
////////////////////////////////////////////////////////////////////////////////
endsnippet

Most helpful comment

@codybuell Try this:

post_expand "vim.command('call timer_start(0, {-> feedkeys(\"\eR\", \"in\")})')"
snippet // "comment block" b
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// ${0}  <---- want to add bits here while keeping this aligned right ---->   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
endsnippet

Or maybe this:

post_jump "if snip.tabstop == 0: vim.command('call timer_start(0, {-> feedkeys(\"\eR\", \"in\")})')"
snippet // "comment block" b
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// ${0}  <---- want to add bits here while keeping this aligned right ---->   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
endsnippet

@ColinKennedy

Try this:

post_expand "vim.command('call timer_start(0, {-> feedkeys(\"\e\", \"in\")})')"
snippet test "A test snippet"
testout
endsnippet

All 4 comments

I'd also like to know that answer to this, though for a slightly different purpose. I want a snippet that returns back to Normal mode, once its done expanding. I've tried several methods and syntaxes - using post_expand, post_jump, using vimscript or using python to call vimscript. I haven't found a method to do it yet.

For reference, this is the kind of syntax I was expecting, which is nearly the same as @codybuell 's code.

post_expand "vim.command('stopinsert')
snippet test "A test snippet"
testout
endsnippet

or maybe something like

snippet test2 "Another test"
testout`!v execute("normal! \<esc>")`
endsnippet

@codybuell Try this:

post_expand "vim.command('call timer_start(0, {-> feedkeys(\"\eR\", \"in\")})')"
snippet // "comment block" b
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// ${0}  <---- want to add bits here while keeping this aligned right ---->   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
endsnippet

Or maybe this:

post_jump "if snip.tabstop == 0: vim.command('call timer_start(0, {-> feedkeys(\"\eR\", \"in\")})')"
snippet // "comment block" b
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// ${0}  <---- want to add bits here while keeping this aligned right ---->   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
endsnippet

@ColinKennedy

Try this:

post_expand "vim.command('call timer_start(0, {-> feedkeys(\"\e\", \"in\")})')"
snippet test "A test snippet"
testout
endsnippet

Works and also runs quickly. This is perfect. Thank you!

@lacygoill Ah, clever! Works very well!

Was this page helpful?
0 / 5 - 0 ratings