4

In Ultisnips, is there a way to create a snippet that will replace empty space in the snippet with a * character upon exiting Insert mode (or as I type)?

For example, I have a snippet that looks like so:

snippet cch
/******************************/
/* ${1} */
/******************************/
endsnippet

After expanding this snippet, I would like to fill the space around the input ${1} with * characters after exiting Insert mode such that the width of this line will match the lines above and below.

So if I type cch <tab> and then Function Prototypes <Esc> it will look like the following:

/******************************/
/***** Function Prototypes ****/
/******************************/

Is this possible?

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
Jin
  • 185
  • 4
  • I don't know how exactly it should be but I have a guess. You should use python interpolation on ultisnips and inside it len("your string"). here a screencast about python interpolation in ultisnps: http://vimcasts.org/episodes/ultisnips-python-interpolation/ – SergioAraujo Jan 23 '18 at 09:19

1 Answers1

1

In my case I have found in plugged/vim-snippets/UltiSnips/all.snippets a snippet called box that makes something like that:

----------------------
-  some text inside  -
----------------------

After reading a little bit more the code I figured out that if you set your filetype like :setf c and type box<tab>you will get your something like:

/*************
*  my text  *
*************/

This means you just have to make a slightly different version of all.snippets

SergioAraujo
  • 1,165
  • 11
  • 12