+2  A: 

I would create a bundle command to do this.

You can take editor selection as input to your script, then replace it with the result of execution. This command, for example, will take a selected number and print the character '#' that number of times.

python -c "print '#' * $TM_SELECTED_TEXT"

Of course this example doesn't allow you to specify the character, but it gives you an idea of what's possible.

pjbeardsley
+1  A: 

By taking the

python -c "print '#' * $TM_SELECTED_TEXT"

a step further, you can duplicate the examples you gave in the question.

Just make a snippet, called divider or something, set the tab trigger field to something appropriate '--' for example, then enter something like:

`python -c "print '_' * $TM_COLUMNS"`

Then when you type --⇥ (dash dash tab), you should get a divider of the correct width.

True, you've lost some of the terseness that you get from vim, but this is far easier to reuse, and you only have to type it once. You can also use whatever language you like.

Matt
I'm missing something: how do you reuse this? The question was about performing an action, not just inserting a character. Do I have to write a new Python program for every action I want to repeat?
Ken
A: 

Inspired by the other answers. Make a snippet with the following:

`python -c "print ':'.join('$TM_SELECTED_TEXT'.split(':')[:-1]) * int('$TM_SELECTED_TEXT'.split(':')[-1])"`

and optionally assign a key sequence to it, e.g. CTRL-SHIFT-R

If you type -x:4, select it, and call the snippet (by it's shortcut for example), you'll get "-x-x-x-x".

You can also use ::4 to obtain "::::".

The string you repeat is enclosed in single quotes, so to repeat ', you have to use \'.

Serge