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

Remove "dd" key binding? #4765

Open
mgeier opened this issue Jun 22, 2018 · 5 comments
Open

Remove "dd" key binding? #4765

mgeier opened this issue Jun 22, 2018 · 5 comments

Comments

@mgeier
Copy link
Contributor

mgeier commented Jun 22, 2018

I really love that it is possible to move down and up between cells with "j" and "k"! I use this all the time!

It was't a surprise to me as a long-time Vim user, that I can remove cells with "dd", just like I can use it to remove lines in Vim.

Then, however, the next logical thing would be to use "p" (which is supposed to mean "put") to re-insert the cell that I removed with "dd" back in after the current cell. This doesn't work, though.

Even worse, once I realize that I cannot get my deleted cell back, I immediately try to undo the deletion with "u" (which obviously is supposed to mean "undo"). But this doesn't work, either! (I later found out that the "undo" button is "z".)

If "dd" is supported, it would also make sense to support "yy" (short for "yank line", where "yank" is the Vim term for "copy"). This doesn't work either (but "c" can be used instead).

AFAICT, "j", "k", "dd" are the only Vim-like keys?

"dd" on its own doesn't make too much sense, so I think it should be either removed or it should be extended with "p" and "u" and probably "yy".

It looks like "yy", "p" and "u" have already the existing key bindings "c" (copy), "v" (paste) and "z" (undo).

I assume the idea of "c", "v" and "z" comes from the common key bindings "ctrl-c", "ctrl-v" and "ctrl-z", which I think is easy to teach to beginners.

In the end, it turns out that whenever I want to use "dd", I can as well use "x". This does the same thing with a minor difference: "dd" doesn't put the deleted cell into the clipboard and therefore it cannot be re-inserted later. But this behavior is inconsistent with what "dd" does in Vim, because there the deleted line will end up in the clipboard!

Long story short, I hereby suggest to remove "dd" from the key bindings.

@ian-r-rose
Copy link
Member

As a vim user I have also found these key-bindings surprising, and I don't particularly like them for the reasons you have laid out, @mgeier.

That being said, one of our core goals for JupyterLab right now is feature parity with the classic notebook, which does use these commands. For that reason I don't think we should change them by default right now.

We do have the ability for users to change the keyboard shortcuts for various commands using the Advanced Settings Editor, and it is possible to make all of the changes you suggest on a per-user basis (p, yy, u etc). It should even be possible to package these changes as a small JupyterLab extension.

Finally, I will note that there is a nice project for adding vim-like bindings to notebooks in JupyterLab which you may or may not be aware of: https://github.com/jwkvam/jupyterlab-vim
I think it implements many of these shortcuts in a more consistent, vimmy way.

@mgeier
Copy link
Contributor Author

mgeier commented Jul 2, 2018

OK, I understand feature parity, but do we also want "bug parity"? I hope not!

IMHO this is definitely a bug, but it can be seen in two different ways (with different solutions):

  1. "dd" alone, without it's friends, doesn't make sense. Solution: either delete it (my favorite) or add the other aforementioned key bindings (and probably more).
  2. Unlike the well-known Vim behavior, "dd" doesn't put the cell(s) into the clipboard. Solution: "dd" should actually become a key binding for "cut cells" instead of "delete cells".

It's great that users can customize key bindings, but that makes it an even less severe change to remove the "dd" key binding.

And yes, I already know jupyterlab-vim. It sounds great, but when I last tried it I couldn't get out of insert mode back into command mode. I should try it again, probably now it works for me ...

@egorananyev
Copy link

egorananyev commented Dec 12, 2019

I agree with @mgeier, this is super dangerous! As a vim user, my first instinct is to either paste the deleted cell or undo the action. Because of the difference in the shortcuts, it's really easy for a novice user to try pressing "u" in hopes of undoing the action (especially upon discovering that the cell is not stored in the clipboard). The ensuing panic and misclicks may very well render "z" futile... As it happened to me a few minutes ago!

Although, instead of removing the "dd" shortcut by default altogether, I'd suggest:

  1. remapping the "dd" behavior to cutting the cell (instead of deleting completely);
  2. adding "u" key to undo (in addition to the 'z').

Fortunately, the above is easily implemented on a custom setup, although I don't see why this can't be the default behavior. The following works for me, and I haven't discovered any conflicts so far (should be inserted into Settings -> Advanced Settings Editor -> Keyboard Shortcuts -> User Preferences [the right panel]):

{
    "shortcuts": [
        {
            "command": "notebook:undo-cell-action",
            "keys": [
                "U"
            ],
            "selector": ".jp-Notebook:focus"
        },
        {
            "command": "notebook:cut-cell",
            "keys": [
                "D",
                "D"
            ],
            "selector": ".jp-Notebook:focus"
        },
        {
            "command": "notebook:paste-cell-below",
            "keys": [
                "P"
            ],
            "selector": ".jp-Notebook:focus"
        },
        {
            "command": "notebook:paste-cell-above",
            "keys": [
                "Shift P"
            ],
            "selector": ".jp-Notebook:focus"
        }
    ]
}

(I added "P" and "Shift P" for paste-below and paste-above behavior, respectively, to match that of vim -- again seems like there are no conflicts.)

ianhi added a commit to ianhi/jupyterlab that referenced this issue Sep 6, 2020
This aligns with what would be expected from vim and makes it more difficult for a user to accidently lose work. Fixes jupyterlab#4765
ianhi added a commit to ianhi/jupyterlab that referenced this issue Sep 6, 2020
As far as I can tell these don't conflict with any existing shortcuts. This also adds the ability to paste above, which was missing from the default shortcuts. Based on jupyterlab#4765 (comment)
ianhi added a commit to ianhi/jupyterlab that referenced this issue Sep 24, 2020
This aligns with what would be expected from vim and makes it more difficult for a user to accidently lose work. Fixes jupyterlab#4765
ianhi added a commit to ianhi/jupyterlab that referenced this issue Sep 24, 2020
As far as I can tell these don't conflict with any existing shortcuts. This also adds the ability to paste above, which was missing from the default shortcuts. Based on jupyterlab#4765 (comment)
@ianhi ianhi mentioned this issue Sep 24, 2020
3 tasks
ianhi added a commit to ianhi/jupyterlab that referenced this issue Sep 29, 2020
This aligns with what would be expected from vim and makes it more difficult for a user to accidently lose work. Fixes jupyterlab#4765
ianhi added a commit to ianhi/jupyterlab that referenced this issue Sep 29, 2020
As far as I can tell these don't conflict with any existing shortcuts. This also adds the ability to paste above, which was missing from the default shortcuts. Based on jupyterlab#4765 (comment)
ianhi added a commit to ianhi/jupyterlab that referenced this issue Oct 4, 2020
This aligns with what would be expected from vim and makes it more difficult for a user to accidently lose work. Fixes jupyterlab#4765
ianhi added a commit to ianhi/jupyterlab that referenced this issue Oct 4, 2020
As far as I can tell these don't conflict with any existing shortcuts. This also adds the ability to paste above, which was missing from the default shortcuts. Based on jupyterlab#4765 (comment)
ianhi added a commit to ianhi/jupyterlab that referenced this issue Oct 4, 2020
This aligns with what would be expected from vim and makes it more difficult for a user to accidently lose work. Fixes jupyterlab#4765
ianhi added a commit to ianhi/jupyterlab that referenced this issue Oct 4, 2020
As far as I can tell these don't conflict with any existing shortcuts. This also adds the ability to paste above, which was missing from the default shortcuts. Based on jupyterlab#4765 (comment)
ianhi added a commit to ianhi/jupyterlab that referenced this issue Oct 4, 2020
As far as I can tell these don't conflict with any existing shortcuts. This also adds the ability to paste above, which was missing from the default shortcuts. Based on jupyterlab#4765 (comment)
ianhi added a commit to ianhi/jupyterlab that referenced this issue Oct 4, 2020
This aligns with what would be expected from vim and makes it more difficult for a user to accidently lose work. Fixes jupyterlab#4765
ianhi added a commit to ianhi/jupyterlab that referenced this issue Oct 4, 2020
As far as I can tell these don't conflict with any existing shortcuts. This also adds the ability to paste above, which was missing from the default shortcuts. Based on jupyterlab#4765 (comment)
@firai
Copy link
Contributor

firai commented Oct 11, 2023

For JL 3 and 4, the notebook shortcuts are in the jupyterlab-vim plugin, and d, d binding cuts cells as proposed. I believe this issue can be closed now?

@mgeier
Copy link
Contributor Author

mgeier commented Oct 12, 2023

That's great news!
The Vim mode seems to be much improved, maybe I can start using it again.

I can confirm that dd stored the deleted cells in the clipboard and they can be inserted again with p.
Also yy seems to work as expected. And, most importantly, u does undo!

However, Ctrl-R does not redo, instead it tries to reload the page in the browser.
Interestingly, it does work as expected within a cell (in normal mode).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants