Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black hole register in Vim mode #15367

Closed
1 task done
idr4n opened this issue Jul 28, 2024 · 6 comments
Closed
1 task done

Black hole register in Vim mode #15367

idr4n opened this issue Jul 28, 2024 · 6 comments
Labels
enhancement [core label] vim

Comments

@idr4n
Copy link

idr4n commented Jul 28, 2024

Check for existing issues

  • Completed

Describe the feature

To my knowledge, Zed's Vim mode already has some registers implementation (namely + and *).

It would be great if the "black hole" register _ is also added, so I can define a mapping for d in which it performs the delete operation without saving it to any register. For example, I would like to define these keymaps:

"d d": ["workspace::SendKeystrokes", "\" _ d d"]
"D": ["workspace::SendKeystrokes", "\" _ D"]
"d i w": ["workspace::SendKeystrokes", "\" _ d i w"]

Similarly, when I paste on a selection (visual mode), I don't want to loose the previous yanked text:

"p": ["workspace::SendKeystrokes", "\" _ d P"]

Thanks in advance!

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

No response

@idr4n idr4n added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Jul 28, 2024
@notpeter notpeter added vim and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Jul 28, 2024
@baptisteArno
Copy link

No workaround for this? I really don't like that behavior 🙄

@ConradIrwin
Copy link
Member

The black hole register was fixed in normal mode in v0.153 (and in visual mode after #18418)

@idr4n
Copy link
Author

idr4n commented Sep 27, 2024

@ConradIrwin thanks a lot for looking into this.

I just tested it out, and while it works if I use the blackhole register manually (e.g., entering "_dd deletes the whole line without yanking it or copying it to the clipboard when "use_system_clipboard": "always"), I still haven't managed to use it in a keymap. For example, this is not working for me:

  {
    "context": "Editor && vim_mode == normal",
    "bindings": {
      "d d": ["workspace::SendKeystrokes", "\" _ d d"],
      "x": ["workspace::SendKeystrokes", "\" _ x"]
      "d i w": ["workspace::SendKeystrokes", "\" _ d i w"]
    }
  },

It seems like any mention to the Vim registers in the documentation has been removed as well. Perhaps I'm missing something. Apologies if I am.

Thanks again!

@alejandrovrojas
Copy link

@ConradIrwin I'm also struggling with remapping d to the black hole register. Are there any workarounds in the current implementation?

@ConradIrwin
Copy link
Member

workspace::SendKeystrokes is unfortunately recursive (it's on my list to fix this; and maybe give it a better syntax). You have to first bind the "d"/"x" to a different key, this should work:

{
    "context": "Editor && vim_mode == normal",
    "bindings": {
      "ctrl-shift-d": ["vim::PushOperator", "Delete"],
      "ctrl-shift-x": "vim::DeleteRight",
      "d d": ["workspace::SendKeystrokes", "\" _ ctrl-shift-d d"],
      "x": ["workspace::SendKeystrokes", "\" _ ctrl-shift-x"],
      "d i w": ["workspace::SendKeystrokes", "\" _ ctrl-shift-d i w"]
    }
  }

@idr4n
Copy link
Author

idr4n commented Oct 19, 2024

Nice! Thanks a lot @ConradIrwin. That is indeed working for me.

This is a full set of keybindings adjustments that I would normally use:

  {
    "context": "Editor && vim_mode == normal",
    "bindings": {
      "ctrl-shift-d": ["vim::PushOperator", "Delete"],
      "ctrl-shift-x": "vim::DeleteRight",
      "ctrl-shift-c": ["vim::PushOperator", "Change"],
      "ctrl-shift-cmd-c": "vim::ChangeToEndOfLine",
      "d d": ["workspace::SendKeystrokes", "\" _ ctrl-shift-d d"],
      "d e": ["workspace::SendKeystrokes", "\" _ ctrl-shift-d e"],
      "d i w": ["workspace::SendKeystrokes", "\" _ ctrl-shift-d i w"],
      "x": ["workspace::SendKeystrokes", "\" _ ctrl-shift-x"],
      "c l": ["workspace::SendKeystrokes", "\" _ ctrl-shift-c l"],
      "c c": ["workspace::SendKeystrokes", "\" _ ctrl-shift-c c"],
      "c e": ["workspace::SendKeystrokes", "\" _ ctrl-shift-c e"],
      "c i w": ["workspace::SendKeystrokes", "\" _ ctrl-shift-c i w"],
      "C": ["workspace::SendKeystrokes", "\" _ ctrl-shift-cmd-c"],
      "m m": ["workspace::SendKeystrokes", "\" + ctrl-shift-d d"],
      "m e": ["workspace::SendKeystrokes", "\" + ctrl-shift-d e"],
      "m i w": ["workspace::SendKeystrokes", "\" + ctrl-shift-d i w"]
    }
  },
  {
    "context": "Editor && vim_mode == visual",
    "bindings": {
      "ctrl-shift-d": "vim::VisualDelete",
      "ctrl-shift-x": "vim::VisualDelete",
      "ctrl-shift-c": "vim::Substitute",
      "d": ["workspace::SendKeystrokes", "\" _ ctrl-shift-d"],
      "x": ["workspace::SendKeystrokes", "\" _ ctrl-shift-x"],
      "c": ["workspace::SendKeystrokes", "\" _ ctrl-shift-c"],
      "m": ["workspace::SendKeystrokes", "\" + ctrl-shift-d"]
    }
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [core label] vim
Projects
None yet
Development

No branches or pull requests

5 participants