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

Missing VS Code keybindings for duplicating and moving lines #4703

Closed
1 task done
ryanwinchester opened this issue Jun 15, 2023 · 21 comments
Closed
1 task done

Missing VS Code keybindings for duplicating and moving lines #4703

ryanwinchester opened this issue Jun 15, 2023 · 21 comments
Labels
editor Feedback for code editing, formatting, editor iterations, etc enhancement [core label] good first issue Issue suitable for first-time contributors

Comments

@ryanwinchester
Copy link

ryanwinchester commented Jun 15, 2023

Check for existing issues

  • Completed

Describe the feature

A) Moving lines or selections

Was partially mentioned in #6079 but not addressed (and I haven't seen another issue yet with these ones).

alt-up move current line (or selected lines) up
alt-down move current line (or selected lines) down

B) Duplicating lines or selections

alt-shift-up duplicate current line (or selected lines) above
alt-shift-down duplicate current line (or selected lines) below

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

VS Code behaviour on duplicating and moving line(s):

Screen.Recording.2023-06-14.at.9.56.43.PM.mov
@ryanwinchester ryanwinchester added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Jun 15, 2023
@ryanwinchester
Copy link
Author

ryanwinchester commented Jun 15, 2023

Update, found similar in Zed's Sublime Bindings

Found the line-moving in Zed's Sublime Bindings as:

{
    "ctrl-cmd-up": "editor::MoveLineUp",
    "ctrl-cmd-down": "editor::MoveLineDown",
}

And The duplicating (alt-shift-down) would be similar to Zed's Sublime binding: "cmd-shift-d": "editor::DuplicateLine"

So now I have this

// ~/.config/zed/keymap.json
[
  // Additional VS Code bindings...
  {
    "context": "Editor",
    "bindings": {
      "alt-up": "editor::MoveLineUp",
      "alt-down": "editor::MoveLineDown",
      "alt-shift-down": "editor::DuplicateLine"
    }
  }
]

This actually covers most of my use-cases. Even though it's not smart with indents like vscode (see screen-recording above), it's not the end of the world.

When #5448 drops I can probably main Zed without pain.

@ryanwinchester ryanwinchester changed the title Missing keybindings for duplicating and moving lines Missing VS Code keybindings for duplicating and moving lines Jun 15, 2023
@hovsater
Copy link
Contributor

@ryanwinchester can I close this one out given that you found the commands you were looking for? There's definitely some room for improvement, but the core functionality should all be there. 🙂

@hovsater hovsater added editor Feedback for code editing, formatting, editor iterations, etc and removed triage Maintainer needs to classify the issue labels Jun 15, 2023
@ryanwinchester
Copy link
Author

ryanwinchester commented Jun 15, 2023

@hovsater I left it in case we had something to track with being smart about indentation levels and “duplicate above” functionality, but I’m okay with closing. 👍

@JosephTLyons JosephTLyons removed the admin read Pending admin review label Jun 18, 2023
@OzzyCzech
Copy link

There is also missing CMD+D for line duplications

[
  {
    "context": "Editor",
    "bindings": {
      "alt-up": "editor::MoveLineUp",
      "alt-down": "editor::MoveLineDown",
      "alt-shift-down": "editor::DuplicateLine",
      "cmd-d": "editor::DuplicateLine"
    }
  }
]

@designbyadrian
Copy link

@hovsater Maybe this deserves a new card, but after editor::DuplicateLine, the editor::MoveLineUp and editor::MoveLineDown commands no longer work. Clicking outside the text brings the functionality back. So, in my humble opinion, the task isn't done because the functionality is faulty.

@JosephTLyons JosephTLyons transferred this issue from zed-industries/community Jan 24, 2024
@LinusU
Copy link

LinusU commented Feb 3, 2024

Slightly related, but I'm also trying to copy over all my VS Code bindings and since I couldn't find "move line up" or something similar in the documentation, I found this thread very helpful!

I also missed cmd-shift-k to delete the current line, it was easy to add:

  "cmd-shift-k": "editor::DeleteLine"

@damnsamn
Copy link

@ryanwinchester can I close this one out given that you found the commands you were looking for? There's definitely some room for improvement, but the core functionality should all be there. 🙂

@hovsater I'd not consider the core functionality to be there currently.

In VS code, you can alt-shift-up as well as alt-shift-down to duplicate lines in those corresponding directions. If there were a way to chain multiple functions for one binding (eg. ["editor::DuplicateLine", "editor::MoveLineUp"], I think that would mean the core functionality is accounted for.

@carlosbaraza
Copy link

It may sound simplistic, but I think these missing shortcuts are a major blocker for adoption by VS Code users. A few of my colleagues completely dismissed Zed because it just takes some muscle memory to get used to the new shortcuts. A better strategy for Zed would be to fully match all the VS Code shortcuts out of the box, if not by default, with a simple button to get all the bindings setup. This will remove a big part of the friction.

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Feb 15, 2024

We have dedicated keymaps for other editors, including VSCode.
People had added more bindings to those in PRs like #7464 (that was for Intellij, but the idea is exactly the same), so, presumably, somebody can come and add those into the VSCode keymap too?
Seems like it would need less characters typed than for any of the messages above.

@ryanwinchester
Copy link
Author

We have dedicated keymaps for other editors, including VSCode. People had added more bindings to those in PRs like #7464 (that was for Intellij, but the idea is exactly the same), so, presumably, somebody can come and add those into the VSCode keymap too? Seems like it would need less characters typed than for any of the messages above.

Is there both a duplicate line above and duplicate line below now? Or still just "editor::DuplicateLine"?

@SomeoneToIgnore
Copy link
Contributor

Oh, that's the point, I see (sorry, starting to forget what VSCode actions are at this point).
We have exactly one duplicate line action now:

DuplicateLine,

and that one is duplicating things below.

It feels relatively simple to add another action (and a test) to duplicate above too, but indeed it's more work and characters typed than any of comments above 🙂

@ryanwinchester
Copy link
Author

ryanwinchester commented Feb 15, 2024

I will learn rust someday, but it's not today 😅

@SomeoneToIgnore SomeoneToIgnore added the good first issue Issue suitable for first-time contributors label Feb 15, 2024
@carlosbaraza
Copy link

I didn't know Zed had some keymap files for other editors. Maybe those keybinding options could be added to a menu where a simple non contributor user could see the list of default available keymaps to quickly choose their preferred keymap without having to dig inside the Zed GitHub issues + Zed codebase + figure out how to do key bindings?

At this point I am not a code contributor to Zed, so the best I can do is to contribute to the discussion, if that is something that is appreciated by the community. These code changes might be obvious/easy to the committed contributor, but newcomers could spend a significant amount of time to resolve them. Maybe their two cents are still valuable to the community?

@SomeoneToIgnore
Copy link
Contributor

Discoverability is always a problem for developers, so that's why I always ask external people to add to docs: they know it better.

For me, that was "obvious" (not for others, as it's clear to see) as there's a cmd-shift-p universal "execute everything" thing that contains base keymaps:
image

and also there are docs on the topic: https://github.com/zed-industries/zed/blob/main/docs/src/configuring_zed__key_bindings.md

At this point, I'm clueless what else could be done to make it more visible, but anybody is welcome to bring ideas on making things better.

@josfaber
Copy link

Added cmd-shift-k also

[
  {
    "context": "Editor",
    "bindings": {
      "alt-up": "editor::MoveLineUp",
      "alt-down": "editor::MoveLineDown",
      "alt-shift-down": "editor::DuplicateLine",
      "cmd-d": "editor::DuplicateLine",
      "cmd-shift-k": "editor::DeleteLine"
    }
  }
]

@JosephTLyons
Copy link
Contributor

I think these have landed in Zed v0.126.0, so I'll close this out.

@Moshyfawn
Copy link
Contributor

Moshyfawn commented Mar 8, 2024

I think these have landed in Zed v0.126.0, so I'll close this out.

I'm not sure that editor::DuplicateLine fulfils this requirement, if that's what you're referring to.

@Banyc
Copy link

Banyc commented Mar 10, 2024

@Moshyfawn I have investigated a bit and i see this:
image

In the future release it will be alt-shift-up and alt-shift-down.

@Moshyfawn
Copy link
Contributor

In the future release it will be alt-shift-up and alt-shift-down.

I see! Thanks for the info, it does make sense 👍

@acusti
Copy link

acusti commented Mar 26, 2024

for anyone who stumbles across this issue because they were used to the previous non-vscode-based key bindings (which i believe were based on atom’s key bindings) and they want those key bindings back, open your key bindings config (Zed › Settings… › Open Key Bindings or from the command-palette, zed: open keymap) and paste in the following config:

[
    {
        "context": "Editor",
        "bindings": {
            "ctrl-shift-k": "editor::DeleteLine",
            "cmd-shift-d": "editor::DuplicateLine",
            "ctrl-cmd-down": "editor::MoveLineDown",
            "ctrl-cmd-up": "editor::MoveLineUp"
        }
    }
]

(there are probably more, but those were the three that i ran into right away)

@croustibat
Copy link

for Zed 0.139.3 you need to specify DuplicateLineDown or DuplicateLineUp.
Here is the one working for me :

[
  {
    "context": "Editor",
    "bindings": {
      "cmd-up": "editor::MoveLineUp",
      "cmd-down": "editor::MoveLineDown",
      "cmd-shift-d": "editor::DuplicateLineDown"
    }
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor Feedback for code editing, formatting, editor iterations, etc enhancement [core label] good first issue Issue suitable for first-time contributors
Projects
None yet
Development

No branches or pull requests