How can i generate number for same piece of text using VS Code - function

i have many pieces of code same for example like this
alt="Greece"
alt="Greece"
alt="Greece"
alt="Greece"
Can i somehow modify it to this? Is there any kind of function like in Excel or something like that please? Imagination write it manualy each is horrible
alt="Greece 1"
alt="Greece 2"
alt="Greece 3"
...
alt="Greece 200"

You can use the extension Regex Text Generator
select the word Greece
select all cases you want with
Ctrl+D multiple times
Ctrl+Shift+L to select all
use Shift+Alt+Click to create multiple cursors
if needed RightArrow to get all cursors after the word Greece
execute command: Generate text based on Regular Expression (regex)
As Original Text Regex use: .*
As Generator Regex use: {{=i+1}} (watch the space as first char)
Look at the preview, use Esc to cancel and Enter to accept
You can use any calculation based on i you want and you can also match number in the selected text and use that in the calculation N[...].
You can also add the word Greece by using Greece {{=i+1}}

You have a couple of options. First, using the extension, Find and Transform (disclaimer, I wrote that extension, this is very easy. Make this keybinding in your keybindings.json (after installing the extension):
{
"key": "alt+n", // whatever keybinding you like
"command": "findInCurrentFile",
"args": {
"find": "(alt=\"Greece\")",
"replace": "$1 ${matchNumber}",
"isRegex": true
}
},
Actually you can make it even easier if you first select what you want to modify (see the demo below). Then use this simple keybinding:
{
"key": "alt+n",
"command": "findInCurrentFile",
"args": {
"replace": "$1 ${matchNumber}", // what you select will be put into $1
"isRegex": true
}
},
Another option - not quite as easy
Snippets have a variable $CURSOR_NUMBER which is useful here.
Make this keybinding:
{
"key": "alt+n",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "$TM_SELECTED $CURSOR_NUMBER"
},
"when": "editorHasSelection"
},
Do a find on your desired text match: alt="Greece"
Ctrl+Shift+L to select all occurrences of the find match.
Trigger the snippet via its keybinding.
Demo of this method:
So this second method is more steps but doesn't require an extension.

Related

VS Code editor: how select everything until next tag - or next occurent of <

There are keyboard shortcuts to select everything between matching brackets and to grow and shrink your selecting, however sometimes there is another markup inside. Is there a way to select everything from coursor to beginning of the next element? For example the cursor sits after the tag. When pressing shortcut I want to:
<p>Select only this text<span>and not this</span>, also not this.</p>
Thank you
You can use the extension Select By.
In your settings.json
"selectby.regexes": {
"till-angle-bracket": {
"forward": "<",
"forwardInclude": false
}
}
You can use the command Select text range based on regex and select till-angle-bracket from the list
or you can add a keybinding
{
"key": "ctrl+shift+y", // or any other key-combo
"when": "editorTextFocus",
"command": "selectby.regex",
"args": ["till-angle-bracket"]
}

Huginn: Extract text from html tag using Website Agent css selector

I'm trying to understand how the web-scraping is done in Huginn but I cannot find proper documentation on the options available.
I'd like to extract the price of the Gold oz. from this website for example:
https://www.xe.com/currencyconverter/convert/?Amount=1&From=XAU&To=USD
For which I use a Huginn Website Agent with this code:
{
"expected_update_period_in_days": "2",
"url": "https://www.xe.com/currencyconverter/convert/?Amount=1&From=XAU&To=USD",
"type": "html",
"mode": "on_change",
"extract": {
"price": {
"css": ".converterresult-toAmount",
"value": "."
}
}
}
I got the css selector using SelectorGadget and I've tried multiple values like: ./node(), string(.), normalize-space(.), . , //text() and others, but I cannot find the way to extract the content of the span html tag that contains that value. Here the code of that section of the web:
<span class="converterresult-toAmount">1,730.35</span>
And what I want to extract is: 1,730.35
i got it working on another site.
i used "xpath" for it.
I used a different site because it wouldn't work on the one you posted.
But i hope this still helps someone.
{
"expected_update_period_in_days": "2",
"url": "https://walletinvestor.com/converter/xau/usd/1",
"type": "html",
"mode": "on_change",
"extract": {
"gold_in_dollar_price": {
"xpath": "/html/body/div[4]/div/div[3]/div[1]/h2/strong/span",
"value": "string(.)"
}
}
}
Here is how you get the XPath of any Element/Object on a website:
(i used Yandex Browser based on chrome for this)
Open the Developer Tools in the Browser (or right click and select "Inspect element code")
Select / Click with the Inspector on your Element/Object
You should now see something like:
<span class="converterresult-toAmount">1,730.35</span>
Right click on this and click: "copy" > "Copy XPath"
Im using Huginn since 2 Days so anyone feel free to tell me any faster way if there is any :)

SublimeText RegReplace Highlighted Text Only

I am trying to use the Sublime Text Plugin RegReplace package so I can highlight a line of text and replace spaces with dashes.
Goal
Hello My Name is Jesse, Highlight, CTRL + . replaces with:
Hello-My-Name-is-Jesse -- for the purpose for saving time creating markdown links.
Currently Working, But Runs Entire File
I would really like this to only replace the text I have highlighted wit a hotkey, is this possible?
I have this in reg_replace_rules.sublime-settings
{
"replacements": {
"replace_spaces_with_dash": {
"find" : "(\\s)",
"replace": "-",
"greedy": true,
"case": false
}
}
}
Here is my User Hotkeys
{
"keys": ["ctrl+."],
"command": "reg_replace",
"args": {"replacements": ["replace_spaces_with_dash"]}
},
However, this replaces the entire file with spaces. I am missing something I hope, I am not sure the scope. Any help would be appreciated.

Sublime Text 3 Vintage mode disable u for switching to lower case

u undos except if you have something selected. Then it turns selection into lower case.
Is there any way to turn of "to lower case" and have u doing undo no matter if you've selected some text or not?
You can simply add a Key Binding to "Key Bindings - User" for the desired key combination that will supersede the default.
On OS X I would go to:
Sublime Text
...Preferences
......Key Bindings - User
On Windows/linux (thanks #MattDMo)
Preferences
...Key Bindings - User
Then I'd add in a new key binding specific to what I want it to do.
If I want to change command + o from open a file to undo I would add
{ "keys": ["command+o"], "command": "undo" }
With that command + o would now undo for me.
More details here: http://docs.sublimetext.info/en/latest/customization/key_bindings.html
You should be able to edit your key bindings to do this. however if you want to turn off vintage altogether, then,
Select the Preferences/Settings - Default menu item
Edit the ignored_packages setting, change it to:
"ignored_packages": ["Vintage"]
There is a guide to remapping keybindings here
here is an example
[
{ "keys": ["j", "j"], "command": "exit_insert_mode",
"context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
]

Alter behavior of "}" shortcut in Sublime Text 3 Vintage Mode

In Sublime Text 3 Vintage Mode, the keyboard shortcut "}" performs the following command:
{
"keys": ["}"],
"command": "set_motion",
"args": {
"motion": "move",
"motion_args": {
"by": "stops",
"empty_line": true,
"extend": true,
"forward": true,
"separators": "",
"word_begin": false
}
}
}
I can't find good documentation for set_motion and I'm not sure where to start to implement this from scratch.
How do I change the behavior so that instead of moving to the next empty line, it moves to the next line with only whitespace?
Thanks!
Can't really help with the set_motion command, but doing it yourself via a plugin shouldn't be to bad. First off, here is a link to the ST3 API docs. You will be creating a sublime_plugin.TextCommand. Of particular interest are view#sel, view#line, and view#substr.
view#sel will get you the position of the cursor(s).
view#line with a point passed in (initially retrieved from view#sel) will create give you a region of the entire line.
view#substr takes the region (result from view#line) and returns the string of the characters in that line. You can use a regular expression to see if that line contains only white space, and place the cursor appropriately. If the line does not meet the requirement, you can increase the second point in the region to move to the next line.
Hope that helps getting you moving in the right direction.
Here is a comment from the softwares author on the options availability for “by”: “stops”
https://forum.sublimetext.com/t/restoring-st2-cursor-move-by-word-behaviour-in-st3-on-os-x/14035
If you need more control, then using the move command with “by”: “stops” should allow more configurability. When using stops, you need to tell the command which logical units to stop on. The options are:
"word_begin": false,
"word_end": false,
"punct_begin": false,
"punct_end": false,
"sub_word_begin": false,
"sub_word_end": false,
"line_begin": false,
"line_end": false,
"empty_line": false,