Reputation: 51
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.
Upvotes: 4
Views: 6574
Reputation: 181339
Here is a simpler way to repeat a sequence of commands without having to learn the HyperSnips syntax I mentioned below.
Using an extension I wrote, Repeat Commands, make this keybinding (in your keybindings.json
):
{
"key": "alt+r",
"command": "repeat-commands.runSequence",
"args": {
"preCommands": [
"cursorColumnSelectLeft" // select the previous character
],
"commands": [
"editor.action.duplicateSelection" // this command will be repeated
],
// "repeat": 5, // hard-code a number if you wish
"repeat": "${getRepeatInput}", // ask the user for the number to repeat
},
// "when": "editorLangId === perl" // if you want to limit it to certain files
},
You first type the character you want to repeat and then trigger the keybinding.
You can run any number of preCommands
that will not be repeated. Then your desired sequence of commands that actaully are repeated. So this extension can be pretty powerful.
Previous answer:
Here is an easy way using HyperSnips - a snippet extension that can use javascript to produce the output. First the demo:
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 LaTeX fraction snippets in VSCode
Upvotes: 4
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
foobar = "1{16}";
Upvotes: 0
Reputation: 10602
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
Upvotes: 0