jupyterlab-contrib / jupyterlab-vim

Vim notebook cell bindings for JupyterLab
https://jupyterlab-contrib.github.io/jupyterlab-vim.html
MIT License
661 stars 43 forks source link

Change the default `notebook:change-cell-to-code` (command+1) shortcut and others. #75

Closed ktakanopy closed 8 months ago

ktakanopy commented 1 year ago

Description

Tried on jupyter-lab vim extension version: 0.15.1

I'd like to remove the change-cell-to-code, change-cell-to-raw and change-cell-to-markdown shortcuts. But I can't. I tried to put this on the user config.

{
    "shortcuts": [
                {
            "args": {},
            "command": "notebook:change-cell-to-code",
            "keys": [
                "Accel 1"
            ],
            "winKeys": {},
            "macKeys": {},
            "linuxKeys": {},
            "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'] .jp-Notebook.jp-mod-editMode",
            "disabled": true
        }
    ]
}

Reproduce

Go to advanced settings, try to override using the above json.

Expected behavior

The shortcut should be removed.

Context

jupyter labextension list:

(studio) sagemaker-user@studio$ jupyter labextension list 
JupyterLab v3.6.0a4
/opt/conda/envs/studio/share/jupyter/labextensions
        nbdime-jupyterlab v2.1.1 enabled OK
        sagemaker_datawrangler v0.3.8 enabled OK (python, sagemaker_datawrangler)
        @jupyter-widgets/jupyterlab-manager v3.1.0 enabled OK (python, jupyterlab_widgets)
        @jupyterlab/git v0.34.2 enabled OK (python, jupyterlab-git)
        @jupyterlab/server-proxy v3.2.1 enabled OK
        @jupyterlab/scheduler v1.1.4 enabled OK
        @amzn/aws-hil-axis-jupyter-lab-extension v5.0.7 enabled OK (python, amzn_aws_hil_axis_jupyter_lab_extension)
        @amzn/sagemaker-ui v5.39.2 enabled OK (python, amzn_sagemaker_ui)
        @amzn/sagemaker-ui-canvas-collaboration v0.0.0 enabled OK (python, @amzn/sagemaker-ui-canvas-collaboration)
        @amzn/sagemaker-ui-theme-dark-jupyterlab v5.39.2 enabled OK (python, amzn_sagemaker_ui_theme_dark_jupyterlab)
        @unfolded/jupyter-map-sdk v1.5.1 enabled OK (python, unfolded.map_sdk)

Other labextensions (built into JupyterLab)
   app dir: /opt/conda/envs/studio/share/jupyter/lab
        @amzn/sagemaker_session_manager v0.2.0 enabled OK
        @axlair/jupyterlab_vim v0.15.1 enabled OK
        jupyterlab-plotly v5.8.2 enabled OK
        sagemaker_notebooks_extension v0.2.0 enabled OK
        sagemaker_sharing_extension v0.1.0 enabled OK

Uninstalled core extensions:
    @jupyterlab/launcher-extension
    @jupyterlab/running-extension

Disabled extensions:
    @jupyterlab/filebrowser-extension:share-file
    @jupyterlab/git:clone
    @jupyterlab/scheduler:IAdvancedOptions

results from uname -a:

(studio) sagemaker-user@studio$ uname -a
Linux default 4.14.296-222.539.amzn2.x86_64 #1 SMP Wed Oct 26 20:36:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
firai commented 9 months ago

Are you just trying to disable the shortcuts, as opposed to assigning another key binding to these commands? Are you adding the preferences to a clean keyboard shortcut configuration (press "Restore to Defaults" in the regular settings editor) or to the default configuration that JL pre-populates? Disabling the bindings seems to work for me either way.

If you're starting from the keyboard shortcuts that JL pre-populates, you need to find the relevant bindings in the pre-populated list and add "disabled": "true" rather than add the whole binding again at the end, as the pre-populated setting usually overrides added settings at the end. I usually set key bindings in a clean key binding settings file to avoid this hassle.

{
    "shortcuts": [
        {
            "command": "notebook:change-cell-to-code",
            "keys": [
                "Accel 1"
            ],
            "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'] .jp-Notebook.jp-mod-editMode",
            "args": {},
            "disabled": "true"
        }
    ]
}

Inability to disable the default keybinding when you try to assign another binding is a known upstream issue: https://github.com/jupyterlab/jupyterlab/issues/15038.

firai commented 8 months ago

I'll close this for now since there wasn't a response. If you're still experiencing this issue after modifying or adding the keyboard shortcut settings per https://github.com/jupyterlab-contrib/jupyterlab-vim/issues/75#issuecomment-1751765432, please reopen with additional details or open a new issue.

As mentioned above, the bug where the default keybinding can't be disabled when you try to assign another binding is being tracked upstream at https://github.com/jupyterlab/jupyterlab/issues/15038.