using regex inside keybindings.json - json

I want to use regex inside of the text in args,
{
"key": "ctrl+shift+r",
"command": "workbench.action.terminal.sendSequence",
"args": { "text":'${file}.'\u000D" }
}
I want to take the name of the file from the file path using this regex - ^\\(.+\\)*(.+)\.(.+)$
or taking the filename in other way,
anyone can help?:)

You do not need to use a regexp, you want to use a different variable:
{
"key": "ctrl+shift+r",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "'${fileBasename}'" }
}
See Variables Reference.

Related

Escaping the '[' bracket in a JSON string without there being another ']'

I am trying to map a custom shortcut to VS code that will paste the following string (which clears the console), using the multi_command tool:
"command": "multiCommand.clearConsole",
"sequence": [
{
"command": "type",
"args": {
"text": "print("\\033\[2J)
}
}
]
I have used a double backslash to escape the first backslash, but I need a way of escaping the '[' open bracket.
Does anyone know if it's possible? or an easier way to do it? I just want to clear the console which is hosted on an external device (interacting via PyCOM Console) and interacts via python command line.
Cheers!
You need to escape the double-quote and the backslash before [, the bracket is a valid JSON character:
{
"command": "multiCommand.clearConsole",
"sequence": [{
"command": "type",
"args": {
"text": "print(\"\\033\\[2J)"
}
}]
}
This keybinding - chose whatever keybinding you want - will clear the console:
{
"key": "ctrl+shift+z",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "clear\u000d" }
}
or you could use that "text" in your macro.
Focus in editor.

Modifying settings.json in vscode to add shell escape flag to pdflatex in latex workshop

I'm new to VSCode and I am setting up LaTeX. I am trying to compile a .tex document that uses minted and thus pdflatex needs the --shell-escape flag. I am trying to modify the settings.json to do this.
I have tried adding the following (found on the internet)
{
"latex-workshop.latex.tools": {
"name": "pdflatex",
"command": "pdflatex",
"args": [
"--shell-escape",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
}
}
However it comes up with an error:
Incorrect type. Expected "array".
This wont even let me try to build with latex workshop. Help would be much appreciated.
I had the same problem and after looking like crazy on the internet I found the solution.
The snippet that you have there is wrongly formatted that's why is complaining.
And is only for the pdf latex recipe.
Here is the snippet that needs to be added to settings.json.
{
...,
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"--shell-escape",
"-pdf",
"%DOC%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"--shell-escape",
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
],
"env": {}
}
],
...
}
I found the solution here in a question related to the pygmentize package

Bracket IDE's Quick Markup equivalent for VS Code

Quick Markup (https://github.com/redmunds/brackets-quick-markup) is an extension available for Brackets IDE for HTML development. The extension can be activated with a shortcut Ctrl+Alt+M. When it is active, we can use custom shortcuts to insert custom HTML tags instead of typing them. For example, to make insert <b></b> tags around a word, we just need to select the word and hit Ctrl+B. The shortcuts and their corresponding tags can be customized.
I'm looking for a similar extension or feature like this in Visual Studio Code. I tried searching but couldn't find anything so far.
keybindings.json
{
"key": "ctrl+b",
"command": "editor.emmet.action.wrapWithAbbreviation",
"when": "editorHasSelection",
"args": {
"abbreviation": "b"
}
},
{
"key": "ctrl+shift+b",
"command": "editor.emmet.action.wrapWithAbbreviation",
"when": "editorHasSelection",
"args": {
"abbreviation": "pre>code"
}
},
You can also call it without args and just type the tags every time.
Or just typing anything:
{
"key": "ctrl+b",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "<br />"
}
}

Sublime Text 2 - Key binding for specific language?

Question
What's the proper way to create a key binding for a specific language?
Background
I'd like to insert a semi-colon after each line automatically when working on java files. I've created a macro to accomplish and have been able to bind it to super+enter. Now I'd like to scope the key binding to just java files. What am I doing wrong?
[
{
"keys": ["super+enter"], "command": "run_macro_file",
"args": {"file": "Packages/User/Add Line SemiColon.sublime-macro"},
"context": [
{ "key": "selector", "operator": "equals", "operand": "source.java" }
]
}
]
You're going to love this—the comparison operator that you're looking for isn't equals, it's equal:
Context Operators
equal, not_equal— Test for equality.
regex_match, not_regex_match— Match against a regular expression.
regex_contains, not_regex_contains— Match against a regular expression (containment).
Change that, and you shouldn't have any more trouble.

Opposite of "wrap selection with tag" in Sublime Text 2

Is there a smarter way of removing the tag (let's say using HTML) around a selection in Sublime text 2?
For example if I have a span tag around some text and want to remove both the start and end of this tag (and leave the text inside untouched)...
Or alternative - remove current tag and it's corresponding end tag?
The Emmet plugin (once called Zen Coding) can do what you want. Install it and press Ctrl+Shift+; within a tag's contents to unwrap the tag.
A bit easier way to do this is to use a macro:
unwrap.sublime-macro
[
{
"args":
{
"to": "tag"
},
"command": "expand_selection"
},
{
"args": null,
"command": "copy"
},
{
"args":
{
"to": "tag"
},
"command": "expand_selection"
},
{
"args": null,
"command": "paste_and_indent"
}
]
...with a ctrl+u for example:
{
"keys": ["ctrl+u"],
"command": "run_macro_file",
"args": {"file": "res://Packages/User/unwrap.sublime-macro"}
}
Pros: no plugins required, only default ST functionality. Cons: modifies clipboard data.