Saturday, March 7, 2015

How to set a string variable and print it from an ultisnippet

I am using the UltiSnips plugin and need that my ultisnippets
behave in a little bit different way depending on the last map
or imap command I have executed.

I have tried to do it via registers, as described below.

First, I define some map, e.g.,
map z1 :let @v = "in "<CR>i some text here<Esc>

So, after typing z1, I have the contents of the v register set to 'in '
and can paste it typing "vpa in a normal mode.

Then, I define an ultisnippet as
snippet vuo "some description here"
Some text here `v! <Esc>"vpa` $1 and some text here
endsnippet
but it does not work as desired, probably because I confuse
vimscript with a nomal mode commands.

Here is the relevant help from the Ultisnips plugin:

4.4.2 VimScript: *UltiSnips-vimscript*

You can also use Vim scripts (sometimes called VimL) in interpolation. The
syntax is similar to shellcode. Wrap the code in backticks and to distinguish
it as a Vim script, start the code with '!v'. Here is an example that counts
the indent of the current line:

------------------- SNIP -------------------
snippet indent
Indent is: `!v indent(".")`.
endsnippet
------------------- SNAP -------------------

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: