Insert same text multiple times on one line

I often have to insert sequences like

:1, :2, :3, :4, :5

into a plain text file. That's easy to do with 5 items like in my example but it becomes tedious if I have something like 42 items. Is there a possibility that I only type the colon and have it repeated a number of times on the same line?

I can do the numbering using an extension so it would be nice if multiple cursors would be placed after the inserted colons immediately.

Upvotes: 0

Views: 654

Answers (2)

rioV8
rioV8

Reputation: 28673

You can use the extension Regex Text Generator. You write a Regular Expression that generates your needed text

Type the following in the Generate Box

(:{{=j[0]+1}}, ){10}

You are left with the , at the end

To place the multiple cursors:

  1. Select the generated text
  2. Open the find dialog: Ctrl+F
  3. Enable Find in Selection: Alt+L
  4. Search for :
  5. Add cursors on all selections: Alt+Enter
  6. Move cursor after selection: ArrowRight

Upvotes: 1

Mark
Mark

Reputation: 181339

See Is there a way to insert N times the same characters for some options on inserting repeated text.

Using the HyperSnips approach this snippet in your plaintext.hsnips file will do what you want:

snippet `:\*(\d+)=` "expand" A
``
let howMany = parseInt(m[1]);
let start = 1;
let newStr = '';
for (let index = 0; index < howMany; index++) {
    newStr += `:${start++}, `;
}
rv=`${newStr.slice(0,-2)}`
``
endsnippet

demo of repeating snippet

Since it is just javascript, you can make that snippet as generic as you want.

Upvotes: 1

Related Questions