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

Can't remap Normal mode j to gj or k to gk in notebooks #113

Open
Deeperand opened this issue Sep 22, 2023 · 1 comment
Open

Can't remap Normal mode j to gj or k to gk in notebooks #113

Deeperand opened this issue Sep 22, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Deeperand
Copy link

Deeperand commented Sep 22, 2023

Description

I tried to remap j to gj in normal mode, but it doesn't work. However, if I map M to gj, it will work. However, such map is valid for VISUAL mode.

Reproduce

Setting -> Notebook Vim -> Add with the following parameters

  • Keybinding: j
  • The key sequence to execute: gj
  • Mode: normal (the strange thing is in visual mode the map work)
  • Map function: normap (or map, both can't help this map work)

Then try to jump between a long-line-text, one can see j still jump to the next actual line, not the next visual line

Expected behavior

j should be mapped to gj, and therefore it will jump to next visual line

Context

  • Jupyter Lab version: 4.0.5
  • jupyterlab-vim version: 4.0.3
@Deeperand Deeperand added the bug Something isn't working label Sep 22, 2023
@firai
Copy link
Collaborator

firai commented Sep 29, 2023

I understand you're referring to remapping these keys in notebooks, which is somewhat of a known limitation. Remapping j to gj and k to gk should already work for file editors.

This limitation is because the jupyterlab-vim plugin redefines/hijacks Normal mode j and k in notebook CodeMirror instances to combine regular cursor movement with navigation between cells, which CodeMirror otherwise knows nothing about. If you type in the commands :nnoremap j gj and :nnoremap k gk in a notebook, you should see successful remapping of the keys within the active cell, but the ability to move between cells using j and k in vim Normal mode would be lost. This plugin re-hijacks these keys whenever you switch between cells or between widgets to restore this ability.

In order to remap these keys, we would need to define custom functions to combine moving the cursor by display lines (gj and gk) with navigation between cells. I have created a proof-of-concept for an enhancement to allow remapping these keys at https://github.com/firai/jupyterlab-vim/tree/remap-j-k, but significant work is still required to deal with cursor behavior around edges of cells. Note that the approach taken in that branch is not the only one possible. Contributions, either building off of what I started or independent, are welcome.

@firai firai changed the title Can't remap to swap j and gj (or k and gk) for NORMAL mode Can't remap Normal mode j to gj or k to gk in notebooks Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants