4

I can't find if vscode has a such failure. Is there a way to construct a string with N characters? I explain myselft: I need to wrote an empty string like this:

foobar = "1111111111111111";

There is 16 times characters '1'. Is there a way, like in Vim, to construct the line like this: i wrote 'foobar = "' then i'd make a command to repeat 16 times the character 'i'.

I hope it's clear for you.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
beware
  • 51
  • 1
  • 4
  • Thank you all for your answer. I'll try all these extensions, and choose the one which fit my needs. – beware Jul 31 '20 at 07:09

3 Answers3

2

Here is an easy way using HyperSnips - a snippet extension that can use javascript to produce the output. First the demo:

repeater demo using HyperSnips

The HyperSnips snippet:

snippet `"(.+)\*(\d+)=` "expand" A
``
let origStr = m[1];
let howMany = parseInt(m[2]);
let newStr = origStr.repeat(howMany);
rv=`"${newStr}`
``
endsnippet

This code goes inside a <yourLanguage>.hsnips file to have it run only in that language or all.hsnips to run in all files.

I made it to run inside a "" using this key: (.+)\*(\d+)=

The = is really the trigger - it runs automatically - you could change that to be something else. [The key could be shorter if you didn't care about digits being repeated.]

For more on setting up HyperSnips (which is pretty easy) see VSCode Advanced Custom Snippets

Mark
  • 143,421
  • 24
  • 428
  • 436
0

There currently is no native way, outside of copy/pasting.

You can use Repeat Paste:

Copies selected text and pastes repeatedly based on user input. Functions like Vim yank, paste, and repeat. For example, in Vim you would select the characters you want to copy then type 30p to paste the selected text 30 times.

Select a char and activate your command palette with CTRL + SHIFT + P and type 'Repeat Paste' and it will prompt you for the quantity.

You can assign a shortcut to this command

soulshined
  • 9,612
  • 5
  • 44
  • 79
0

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

foobar = "1{16}";
rioV8
  • 24,506
  • 3
  • 32
  • 49