Specific lines of code in vscode can be linked to via application url as documented here:
https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls
It would be nice to be able right-click on a line of code and get the url in your clipboard. I can't seem to find if there is an existing extension for that feature, wondering if anyone knows.
The use case I can think of is pasting the url into a task manager so when it comes time to work on that line of code, you can easily jump right to it versus trying to remember the code file / LOC
you can use the following task to print the url to the terminal, you can copy it from there
{
"version": "2.0.0",
"tasks": [
{
"label": "file URL",
"type": "shell",
"command": "echo vscode://file${command:extension.commandvariable.file.filePosix}:${lineNumber}",
"problemMatcher": []
}
]
}
It uses the extension Command Variable to get the correct file separators on Windows (/). It only removes the : of the drive, because you don't want that in Cygwin and MSys.
You can try if this works in opening VSC with the file and line number
"command": "echo vscode://file${file}:${lineNumber}",
Related
I write text files in markdown format, in Visual Studio Code. I have a powershell script (.ps1) that I use to convert a markdown file (.md) to a pdf file. I would like to execute the .ps1 by creating a task.
I have tried to create a task:
Ctrl+Shift+P -->
Tasks: configure default build task>open tasks.json file>Others
This is what tasks.json looks like:
{
"version": "0.2.0",
"configurations": [
{
"name": "RUN md to pdf",
"type": "PowerShell",
"program": "C:/Users/tomas/OneDrive/Dokument/_markdown/kandidat/script/_RUN.ps1"
}
]
}
Where _RUN.ps1 is the script I want to execute. Note one thing: the script says "version": "0.2.0". But when I look around for a solution, it the version is "2.0". I have the latest vscode installed (1.63.2), on windows 11.
What I expected to happen: I would have a task called "RUN md to pdf" that I could execute by pressing ctrl+shift+B.
But when I press ctrl+shift+B I just get "No build task to run found..."
Any ideas?
Ok. So I found a solution. Mytasks.json no looks like this:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Create PDF",
"detail": "Use _RUN.ps1 to convert md to pdf with Pandoc",
"command": "C:/Users/tomas/OneDrive/Dokument/_markdown/kandidat/script/_RUN.ps1"
}
]
}
If I press ctrl+shift+B I get the option to choose my task (Create PDF) and the next time I press ctrl+shift+B it will just execute my .ps1 file. Success!
I intend to write a task, that first runs a dev server command, and parallely opens VS code's Simple Browser (Command Pallette -> Simple Browser) to the url.
I dont need the task to dynamically get the url from the dev server.
I've managed to make task to open the Simple Browser using input variable
{
"version": "2.0.0",
"tasks": [
{
"label": "open simple browser",
"command": "${input:openSimpleBrowser}"
}
],
"inputs": [
{
"id": "openSimpleBrowser",
"type": "command",
"command": "simpleBrowser.show",
"args": ["https://xkcd.com"]
}
]
}
One thing that I didn't find the documentation of is to find the name of the command. I found the name simpleBrowser.show by chance in VSCode itself. Apparently, you can get the name of each command in the command palette by:
search the command in the palette first
select the Configure Binding cog icon, which will take you to Keyboard Shortcuts
in the search bar, the name of the command will be written, e.g. #command:simpleBrowser.show
you'll only need the name after : for input variable
In the VS Code terminal, is there a command that will give you the name of the file that you currently have open? e.g. just the file name IndexController.php?
I frequently run a test command in my terminal make test-watch /long/path/to/file.php and I need to right click on the file name and select "copy relative path" to get that path, which I then have to paste in.
It would save me a little bit of hassle if I could add a make test-watch-here that just read from the open file. Is it possible?
You can use the extension Command Variable v1.19.0
With the command extension.commandvariable.inTerminal you can type the result of a command in the terminal.
The extension contains also a command to transform a string with variables to there value.
An example for your case:
{
"key": "ctrl+i f5", // or any other combo
"command": "extension.commandvariable.inTerminal",
"args": {
"command": "extension.commandvariable.transform",
"args": { "text": "${relativeFile}" }
}
}
The key combo works in the editor and the terminal.
See the doc of the extension to see what you can do more with the transform command (like find/replace with regexp)
I have created a keybinding in vscode using this code in keybinding.json file-
{
"key": "f10",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "${file}",
},
"when": "editorFocus"
}
it sends the path of the focused file opened using backslash, like this,
C:\Users\User\Desktop\hello.cpp
it works in cmd. but my git bash needs path using slash.
Is there any way to send path with slash like
C:/Users/User/Desktop/hello.cpp
You need to go upvote this issue:
https://github.com/microsoft/vscode/issues/111457 (Git Bash Terminal Slash issue)
It doesn't look there is a way to do this without grabbing the result in a script and manipulating the string yourself.
I want to test the wildcard treatment of my Python script. Therefore I want to handover a file path which contains wildcards e.g. data/*.xml.
If I call my script directly in the shell
my_script.py data/\*.xml
The escape of the wildcard works fine and the wildcard is seen by my script.
However, I'm not able to achieve this with my launch configuration of vscode.
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: my_script",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/my_script.py",
"console": "integratedTerminal",
"args": ["mine", "${workspaceFolder}/data/\\*.xml"]
}
]
}
This launch fails:
% cd /Users/tom/Documents/evaluate ; env /Users/tom/Library/python3.8/bin/python /Users/tom/.vscode/extensions/ms-python.python-2020.8.103604/pythonFiles/lib/python/debugpy/launcher 52992 -- /Users/tom/Documents/evaluate/my_script.py mine /Users/tom/Documents/evaluate/data/\\*.xml
zsh: no matches found: /Users/tom/Documents/evaluate/data/\*.xml
I tried several other variants to quote the wildcard without success e.g. the shell escape didn't work and the shell expanded the wildcard before the path is handed over to the script.
Any idea how I have to define the path properly in the "args:" of my launch configuration?
It really seems to be a bug. The escaping does not work as expected and differs depending on the used console.
Please refer the discussion in the related Github ticket.