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

Emacs Compatibility Tracking Issue #4856

Open
morgoth opened this issue Mar 30, 2023 · 27 comments
Open

Emacs Compatibility Tracking Issue #4856

morgoth opened this issue Mar 30, 2023 · 27 comments
Labels
enhancement [core label] keymap / key binding Feedback for keyboard shortcuts, key mapping, etc

Comments

@morgoth
Copy link

morgoth commented Mar 30, 2023

Rather than a monolithic "implement emacs in Zed" enhancement request (which is inherently unactionable) this issue is a tracking issue for centralizing various Zed bug fixes and enhancements to better supporting emacs-like compatibility and operation in Zed.

Comments such as "I need emacs mode to switch to Zed!" and the like are unwelcome here.
Please vote with 👍 below instead.

Editor note (@notpeter): Originally this issue was for an emacs keymap, a beta of which shipped in #19605

@JosephTLyons JosephTLyons transferred this issue from zed-industries/keymaps Jul 19, 2023
@JosephTLyons JosephTLyons added enhancement [core label] keymap / key binding Feedback for keyboard shortcuts, key mapping, etc labels Jul 19, 2023
@ozanmakes
Copy link
Contributor

An offical "Emacs mode" would be really nice. There is a couple of example user configurations over here: https://github.com/zed-industries/community/discussions/1653

At the moment the lack of a "mark" command is the biggest holdup. In Emacs, pressing Ctrl+SPC will toggle selection and let you use movement commands to select text without keeping Shift pressed. Any chance this could be added to Zed?

@JosephTLyons JosephTLyons transferred this issue from zed-industries/community Jan 24, 2024
@lvii

This comment was marked as spam.

@yonkeltron

This comment was marked as off-topic.

@lllleonnnn

This comment was marked as spam.

@opsnull

This comment was marked as off-topic.

@DidacBable

This comment was marked as off-topic.

@samin-UMG

This comment was marked as off-topic.

@djhunter67

This comment was marked as off-topic.

@akaihola
Copy link

At the moment the lack of a "mark" command is the biggest holdup. In Emacs, pressing Ctrl+SPC will toggle selection and let you use movement commands to select text without keeping Shift pressed. Any chance this could be added to Zed?

At least there's an issue for this (go and vote!):

@notpeter notpeter changed the title Emacs keymap Emacs Compatibility Tracking Issue Dec 3, 2024
@notpeter
Copy link
Member

notpeter commented Dec 3, 2024

For those following this issue we've recently shipped two emacs-related improvements:

Please try out the Emacs (beta) keymap by triggering the welcome: toggle bas keymap selector:

image

It's very basic at this point, but give it a whirl, happy to consider PRs with improvements / refinements.

Rather than close this issue I've repurposed it as a tracking issue for additional Emacs-related enhancements and I've edited the issue description above to include links to other issues.

One other update, sadly, due to issues with international keyboards we also opted to revert terminal.option_as_meta to default to false again:

If you need emacs/readline style keybinds in your terminal which use meta / alt you will want to add this to your settings.json:

  "terminal": {
    "option_as_meta": true
  }

@jinschoi

This comment was marked as resolved.

@djhunter67

This comment was marked as off-topic.

@pbgc

This comment was marked as resolved.

@dmvianna

This comment was marked as resolved.

github-merge-queue bot pushed a commit that referenced this issue Jan 3, 2025
Various improvements to the emacs compatibility keybindings.

- See also: #4856

Release Notes:

- Improvements to emacs keybindings:
- Better support for running emacs inside Zed terminal (e.g. `ctrl-x
ctrl-c` will quit emacs in terminal not zed)
  - `alt-^` Join Lines
  - `ctrl-/` Undo
  - `alt-.` GotoDefinition and `alt-,` GoBack
  - `ctrl-x h` SelectAll
  - `alt-<` / `alt->` Goto End/Beginning of Buffer
  - `ctrl-g` as Menu::cancel
@rakete

This comment was marked as off-topic.

@notpeter
Copy link
Member

notpeter commented Jan 6, 2025

I've added a bunch of the suggestions provided above and hidden the associated comments to keep this thread from growing out of control. Where possible I'm trying to stick only the actual default emacs keybinds and avoid people's personal binds.

Here are some recent improvements which have made their way into Zed:

@rakete Nifty that There's you've managed to build a Mark mode workaround with AutoHotKey.
As mentioned above, there's also a a dedicated issue:

@dmvianna
Copy link

dmvianna commented Jan 6, 2025

I'm a big fan of occur. Would it be too much to add it to a task? Obviously that's functionality that goes well beyond keybindings.

@notpeter
Copy link
Member

notpeter commented Jan 7, 2025

@dmvianna I don't have any experience using emacs occur but fundamentally it looks quite similar to a Zed Project Search multibuffer. Zed multibuffers support editing across multiple files while paging through search results. Currently multibuffers default to +2 / -2 lines of context above/below the line in question, I imagine it would be possible to create an occur search multibuffer that have 0 lines of context and potentially hide 'expand context up/down' buttons to create a more minimalist view which more closely resembles occur. Feel free to file an issue. To be upfront, it's not something we're likely to immediately prioritize, but it definitely would be worth tracking user interest.

@kzar
Copy link

kzar commented Jan 7, 2025

It might be worth adding "ctrl-o": "editor::Newline" for the editor context?

@notpeter
Copy link
Member

notpeter commented Jan 7, 2025

@kzar Emacs ctrl-o behavior is slightly different that editor::Newline, ctrl-o creates a newline below but does not move the cursor. I would prefer to add support for an optional parameter to the editor::NewlineBelow action so that we could bind "ctrl-o": ["editor::NewlineBelow", {"move_cursor": false}].

Similar to this:

"ctrl-/": ["editor::ToggleComments", { "advance_downwards": false }],

#[derive(PartialEq, Clone, Deserialize, Default)]
pub struct ToggleComments {
#[serde(default)]
pub advance_downwards: bool,
#[serde(default)]
pub ignore_indent: bool,
}

And then add a conditional inside the newline_below to optionally move the cursor.
pub fn newline_below(&mut self, _: &NewlineBelow, cx: &mut ViewContext<Self>) {

@kzar
Copy link

kzar commented Jan 7, 2025

Good point about not moving the cursor, but I don't think that editor::NewlineBelow is right because if you're at the start of a line C-o should move the current line down (or if you're in the middle of a line, it should move the part after your cursor down). Perhaps we could go with your approach to stop the cursor moving, but with editor:Newline?

@kzar
Copy link

kzar commented Jan 8, 2025

"ctrl-t": "editor::Transpose" for the editor context is another one I kept missing. (@notpeter is it helpful if I keep commenting with these, or if not is there a better way to share them that would help?)

@dmvianna
Copy link

dmvianna commented Jan 10, 2025

@dmvianna I don't have any experience using emacs occur but fundamentally it looks quite similar to a Zed Project Search multibuffer.

I opened a feature request, where I delve more deeply into the differences between occur and Zed Project Search Multibuffer: #22943

@dmvianna
Copy link

dmvianna commented Jan 10, 2025

Oh, duh.

"context": "Editor:"

    "ctrl-y": "editor::Paste",
    "alt-w": "editor::Copy",
    "ctrl-w": "editor::Cut",
    "ctrl-?": "editor::Redo",
    "ctrl-shift-n": "editor::SelectDown",
    "ctrl-shift-p": "editor::SelectUp",
    "alt-shift-f": "editor::SelectToNextWordEnd",
    "alt-shift-b": "editor::SelectToPreviousWordStart",
    "ctrl-alt-shift-f": "editor::SelectToEndOfLine",
    "ctrl-alt-shift-b": "editor::SelectToBeginningOfLine"

This below also stops the Assistant from opening at every attempt to run editor::Redo.

"bindings"

  "alt-x": "app_menu::OpenApplicationMenu",
  "ctrl-?": null

And this prevents the cursor movement commands from opening new buffers when reaching beyond the first and last lines of a buffer.

"context": "Workspace:"

  "ctrl-n": null,
  "ctrl-p": null,

@dmvianna
Copy link

dmvianna commented Jan 10, 2025

Another biggie: the kill ring. Basically a copy history that you can browse through by typing alt-y after the first ctrl-y (paste). And all its associated commands, as actually seeing the list of copy items in memory before choosing one (pressing alt-y not preceded by ctrl-y or itself).

There's an issue for it already, it would be nice to have it in the description of this issue too.

@dmvianna
Copy link

Moving around the workspace panes is different from Emacs, which will just cycle through all available buffers and has no default concept of how they're positioned. Zed seems to organise them spatially, so instead of having just the default Emacs ctrl-x o (which I rebinded to alt-o as per Mastering Emacs in my own configuration), I had to use spatial bindings. I dislike it; I find Emacs's approach better, especially when I can use IBuffer to locate buffers by name using ctrl-x b.

In Emacs, I go to the pane I want the buffer to be and switch to it by name. In Zed (at least for now), I have to locate the pane by looking at the tabs, switching to the pane and then choosing the desired tab. Suboptimal.

Here's my current config:

"context": "Workspace"

  "ctrl-x o": "tab_switcher::Toggle",
  "alt-x b": ["workspace::ActivatePaneInDirection", "Left"],
  "alt-x f": ["workspace::ActivatePaneInDirection", "Right"],
  "alt-x p": ["workspace::ActivatePaneInDirection", "Up"],
  "alt-x n": ["workspace::ActivatePaneInDirection", "Down"]

@dmvianna
Copy link

dmvianna commented Jan 10, 2025

pop-global-mark in Emacs takes you back to the last mark, which in Zed it is the same as xref-go-back.
"context": "Pane"

  "alt-,": "pane::GoBack",  // xref-go-back
  "ctrl-x ctrl-space": "pane::GoBack",  // pop-global-mark
  "ctrl-u ctrl-space": "pane::GoForward"  // set-mark-command with negative prefix

Typing ctrl-x ctrl-space fast enough in Zed is tricky. How can I make Zed less impatient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement [core label] keymap / key binding Feedback for keyboard shortcuts, key mapping, etc
Projects
None yet
Development

No branches or pull requests