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

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.

Related

using regex inside keybindings.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.

Forward slashes instead of back in filepath

How do I replace the backslashes with forward slashes in the Visual Studio Code build task argument.
I've tried using backslashes in my Bash command, but the console simply removes the slashes.
"command": "xxxxxxxx.exe",
"type": "shell",
"args": [
"--dir=${workspaceFolder}",
]
In the console it appears to be:
> Executing task: xxxxxxxx.exe --dir=C:UsersUserDesktopProject
But I want it to be:
> Executing task: xxxxxxxx.exe --dir=C:/Users/User/Desktop/Project/
Something using bash built-in ${variable//string/substitution}:
"command": "xxxxxxxx.exe",
"type": "shell",
"args": [
"--dir=${workspaceFolder//\\/\/}",
]
As for me, just switch default shell to cmd done the job. I installed git-bash as my default shell within vscode. When I tried to debug ts file, the shell complained something like your case, the path is a string without any slash or backslash.
This is my launch.json.
{
{
"type": "node",
"request": "launch",
"name": "Debug Current",
"preLaunchTask": "tsc: build - tsconfig.json",
"skipFiles": ["<node_internals>/**"],
"program": "${file}",
"outFiles": ["${workspaceFolder}/dist/*.js"]
}
]
}
Did you double the backslashes? They are a quoting character, so you likely have to use one to quote the next.
$: echo "C:\Users\Public" | sed 's,\\,/,g'
C:/Users/Public
Using parameter expension without spawning a sed -
$: x="C:\Users\Public"
$: echo "${x//\\/\/}"
C:/Users/Public

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 Snippets Keyboard Shortcut

I want to create a custom key binding to trigger the Tools > Snippets overlay. I know sublime uses the show_overlay command and overlay enum, but after trial an error I can't figure out what to set the enum to.
{
"keys": ["shortcut"],
"command": "show_overlay", "args": {"overlay": "some_unknown_command"}
}
I'm not looking to insert a specific snippet, just trigger the overlay.
You can find the command by entering sublime.log_commands(True) in the ST console, then using the menu to display the overlay. It will give you the arguments and command you need to use.
{
"keys": [ <your keys here> ],
"command": "show_overlay",
"args": {
"overlay": "command_palette",
"text": "Snippet:"
}
}