zed icon indicating copy to clipboard operation
zed copied to clipboard

[vim] default keymap supplement

Open 0x2CA opened this issue 1 year ago • 5 comments

Check for existing issues

  • [X] Completed

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

0x2CA avatar Apr 12 '24 03:04 0x2CA

  • Fully agreee on editor::ToggleComments.
  • Fully agree on g ] and g [
  • I think the ctrl-w ones make sense.
  • ] x and [x we already have: https://github.com/zed-industries/zed/blob/6f59515dd1f2823d58c34942df82e8e8d21035cd/assets/keymaps/vim.json#L370-L371

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 ,)

mrnugget avatar Apr 12 '24 04:04 mrnugget

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

0x2CA avatar Apr 12 '24 05:04 0x2CA

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

mrnugget avatar Apr 12 '24 05:04 mrnugget

@mrnugget

  • I already had g c and g c c so those are a welcome addition.
  • Yeah, I don't think we should add space keybindings. I use space as my leader key for my own bindings, but think we need to have some sort of leader support before defaulting anything with a leader key. Would be nice if we could configure a leader key in settings and then was available in the keymap as something like $ZED_LEADER. Similarly, would like to be able to access $ZED_FILE, $ZED_ROW, etc in keymaps, like we can in tasks.
  • I've never, ever used ctrl-w * keybindings in vim so don't have much of an opinion.

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"
  }
},

baldwindavid avatar Apr 12 '24 18:04 baldwindavid

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.

ConradIrwin avatar Apr 12 '24 20:04 ConradIrwin

@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"
      ]
    }
  }

0x2CA avatar Jun 12 '24 06:06 0x2CA

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.

ConradIrwin avatar Jun 12 '24 15:06 ConradIrwin

Binding ctrl-w ... will slow down bare ctrl-w like in #14540, right ?

bersace avatar Jul 16 '24 06:07 bersace

Binding ctrl-w ... will slow down bare ctrl-w like in #14540, right ?

As far as I know if you configure <c-w> and <c-w> x it slows down <c-w>, usually a 1 second delay to determine what keystrokes you end up with, it's usually a good idea to just configure <c-w> to be null and look for <c-w> x to make the new binding

For example, the default keymap image

0x2CA avatar Jul 16 '24 06:07 0x2CA