UV VS Code Task

To create a shortcut in VS Code for running your Python script with uv, follow these steps:

1. Open Keyboard Shortcuts

  1. Press Ctrl+K followed by Ctrl+S to open the Keyboard Shortcuts menu.

2. Add a New Shortcut

  1. In the search bar at the top, type run task.
  2. Find the command Tasks: Run Task and click on the pencil icon next to it to add a new keybinding.
  3. Choose a key combination that you want to use (e.g., Ctrl+Alt+R).

3. Configure the Task

  1. Open the Command Palette by pressing Ctrl+Shift+P.
  2. Type Tasks: Configure Task and select it.
  3. Choose Create tasks.json file from template and then select Others.

4. Edit tasks.json

  1. VS Code will open a tasks.json file. Replace its content with the following configuration:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run Python Script with uv",
            "type": "shell",
            "command": "uv run python ${file}",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "problemMatcher": []
        }
    ]
}

5. Use the Shortcut

Now, you can use the key combination you set (e.g., Ctrl+Alt+R) to run your Python script with uv.

This setup will allow you to quickly run your Python scripts using uv with a simple keyboard shortcut. Let me know if you need any further assistance!