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.
https://zed.dev
Other
39.25k stars 2.03k forks source link

[vim] default keymap supplement #10457

Open 0x2CA opened 2 months ago

0x2CA commented 2 months ago

Check for existing issues

Describe the feature

 {
        "context": "Editor && VimControl && !VimWaiting && !menu",
        "bindings": {
            // put key-bindings here if you want them to work in normal & visual mode
            "ctrl-w z": "workspace::ToggleZoom",
            "ctrl-w t": "terminal_panel::ToggleFocus",
            "space g b": "editor::ToggleGitBlame",
            "space f f": "file_finder::Toggle",
            "space f p": "pane::TogglePreviewTab",
            "space f o": "projects::OpenRecent",
            "space w": "workspace::Save",
            "g ]": "editor::GoToDiagnostic",
            "g [": "editor::GoToPrevDiagnostic",
            "] x": "editor::SelectSmallerSyntaxNode",
            "[ x": "editor::SelectLargerSyntaxNode
}, 
 {
        "context": "Editor && vim_mode == normal && !VimWaiting && !menu",
        "bindings": {
            // put key-bindings here if you want them to work only in normal mode
            "g c c": "editor::ToggleComments"
        }
    },
    {
        "context": "Editor && vim_mode == visual && !VimWaiting && !menu",
        "bindings": {
            // visual, visual line & visual block modes
            "g c": "editor::ToggleComments"
        }
    }

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

No response

mrnugget commented 2 months ago

The space ones I'm not so sure about, since space as a leader is a bit of a custom thing and I don't think we should introduce space as a default-leader thing (I personally use ,)

0x2CA commented 2 months ago

@mrnugget ToggleComments also missing gC functions such as gCi} current [ x and ] x only in normal ,Unable to expand selection about the Leader key

mrnugget commented 2 months ago

First PR here: https://github.com/zed-industries/zed/pull/10461

For the other bindings (ctrl-w ... and space), I'm curious what @ConradIrwin and @baldwindavid think

baldwindavid commented 2 months ago

@mrnugget

Regarding the unimpaired style ] x and [ x, I learned a really cool trick from #9244 - Not really suggesting as a default, but I've been using it a lot.

{
  "context": "Editor && vim_mode == visual && !VimWaiting && !menu",
  "bindings": {
    "v": "editor::SelectLargerSyntaxNode",
    "V": "editor::SelectSmallerSyntaxNode"
  }
},
ConradIrwin commented 2 months ago

Agreed with not having default bindings with a space so everyone has somewhere they can stash their own things.

For panels we've started the convention of :X opening them, so we could add :Blame for git blame (and ensure that :B selects that) and :Projects for recent projects? (similarly :P). Will work fine until we get up to 26 panes and panels (assuming we name them carefully :D).

I think ctrl-w t is not the right "builtin" shortcut for that (use :T or :te, or ctrl-w j once it's open). ctrl-w t is a vim shortcut (though probably not a zed compatible one)

ctrl-w z could work for zoom. I'm not sure we'll ever build vim-style preview panes, so it's probably ok to reuse. I'd also be open to another key, but ctrl-w is pretty full already, so maybe that's the best option.

0x2CA commented 2 weeks ago

@ConradIrwin

Though you cannot operate on arbitrary objects yet, but it is possible to implement gco and gcO in a simple way.

  {
    "context": "Editor && vim_mode == normal && !VimWaiting",
    "bindings": {
      "g c o": ["workspace::SendKeystrokes", "o escape g c c shift-a"],
      "g c shift-o": [
        "workspace::SendKeystrokes",
        "shift-o escape g c c shift-a"
      ]
    }
  }
ConradIrwin commented 2 weeks ago

I think we can take the same general approach for gc as we just did for > where we have a vim wrapper that sets up the selection, calls the editor command, and restores the selection where we want it.

We'll also need to build the gc object to make it work really well though.