zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Home Page:https://zed.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parametrized keymap binding configuration to enable launching external applications like Dash and others.

florinpatrascu opened this issue · comments

Check for existing issues

  • Completed

Describe the feature

Hi!

Is it feasible to improve the support for keymap bindings and enable a definition similar to this?

{
  "bindings":{
    "cmd-shift-h": {
      "command": "editor::OpenUrl",
      "args":{
        "uri": "file:///Applications/Dash.app",
        "keywords": "$ZED_SELECTED_TEXT"
      }
    }
  }
}

or

{
  "bindings": {
    "cmd-shift-h": {
      "command": "editor::OpenUrl",
      "args": "dash://keyword:{$ZED_SELECTED_TEXT})"
    }
  }
}

or, is there some adjacent functionality that could be utilized similarly, such as the (very) new helix-like snippets feature?

Thank you

If applicable, add mockups / screenshots to help present your vision of the feature

No response

You should be able create a task with parameterized arguments (like "${ZED_SELECTED_TEXT}") in your task definition. And then create a key binding which spawns that task by-label name.

Here's a trivial example that worked for me:

//tasks.json
[
  {
    "label": "stat current file",
    "command": "stat",
    "args": ["${ZED_FILE}"]
  }
]
//keymap.json
[
  {
    "context": "Editor",
    "bindings": {
      "ctrl-alt-delete": [
        "task::Spawn",
        {
          "task_name": "stat current file"
        }
      ]
    }
  }
]

Let me know if this doesn't work as expected.
I tested with Zed Preview.

@notpeter thank you for the pointer. it works. And this is what I have in case others are interested:

keymap.json

[
  {
    "context": "Editor",
    "bindings": {
      "ctrl-shift-h": [
        "task::Spawn",
        {
          "task_name": "open Dash"
        }
      ]
    }
  }
]

and in tasks.json:

[
  {
    "label": "open Dash",
    "command": "open dash://elixir%3A$ZED_SELECTED_TEXT",
    // or w/o specifiying the elixir docset:
    //"command": "open dash://$ZED_SELECTED_TEXT",
    "use_new_terminal": false,
    "allow_concurrent_runs": false,
    "reveal": "never"
  }
]

Do you happen to be aware of any Zed variable that stores the word under the cursor? This feature would be beneficial as it would eliminate the need to manually select the word and then use a keyboard shortcut.

ZED_SYMBOL might do this, but I haven't tested. If not, please open a new issue with an enhancement request for this -- it could be useful.

Complete list of available variables is in the task docs:

https://zed.dev/docs/tasks#variables

Ah I just tried $ZED_SYMBOL, but in my case it includes the module name - as I'm editing Elixir source code. I will create a new issue to request this enhancement. Thank you once again for your help, I have what I need for now.