jupyterlab-contrib / jupyterlab-vim

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

Moving cursor up/down jumps to after paragraph in Markdown #23

Closed BrendanMartin closed 3 years ago

BrendanMartin commented 3 years ago

In markdown, using j/k jumps to the end of the paragraph instead of directly vertical.

ScreenCaptureProject16

ianhi commented 3 years ago

This has bothered me as well. This is because codemirror treats each of those paragraphs as a line which you can see if you have a markdown file open in the fileeditor with line numbers: image

And j and k use a custom motion

https://github.com/axelfahy/jupyterlab-vim/blob/8b4b8e9075697cd9301e738b765cd0a69b16ddd7/src/index.ts#L142-L155

so the fix here is probably to mess around in that function: https://github.com/axelfahy/jupyterlab-vim/blob/8b4b8e9075697cd9301e738b765cd0a69b16ddd7/src/index.ts#L74-L75

ianhi commented 3 years ago

Actually this is the correct vim behavior. Here is my native vim:

vim-lines

ianhi commented 3 years ago

Hmm, see also https://vim.fandom.com/wiki/Move_cursor_by_display_lines_when_wrapping

I'm not sure how much of that will translate to codemirror vim, but some of it may be achievable with https://github.com/ianhi/jupyterlab-vimrc

lukashergt commented 3 years ago

A quick

:nmap j gj
:nmap k gk
:vmap j gj
:vmap k gk

will treat wrapped lines like normal lines, if that helps, but I'm unsure whether this is what @BrendanMartin is looking for.

Actually this is the correct vim behavior. Here is my native vim:

I think @BrendanMartin is pointing out that the position/column of the cursor in the line is changing from line to line, which is not correct vim behaviour. In his example the cursor starts out at position/column 52 but then after jkjj it lands on position/column 1 instead of back on position/column 52.

ianhi commented 3 years ago

I think @BrendanMartin is pointing out that the position/column of the cursor in the line is changing from line to line, which is not correct vim behaviour. In his example the cursor starts out at position/column 52 but then after jkjj it lands on position/column 1 instead of back on position/column 52.

oooh good point. And notably that is not the behavior of the most recent codemirror vim binding see: https://codemirror.net/demo/vim.html which gets it correct.

I think this is because the MoveByLinesOrCells is a modified version of this function https://github.com/codemirror/CodeMirror/blob/9d0f9d19de70abe817e8b8e161034fbd3f907030/keymap/vim.js#L1922 which seems have been updated since it was originally adapted for jupyter.

I'll bet that re-porting that function over would fix this - if anyone does that I'm happy to help advise on getting dev setup and whatnot and will review (though I don't think I have merge rights)

ianhi commented 3 years ago

will treat wrapped lines like normal lines, if that helps, but I'm unsure whether this is what @BrendanMartin is looking for.

Oh nice! I'm never quite sure what remaps will actually work in codemirror or not, it can seem so arbitrary at times.

Although it seems that doing this removes the ability go leave a cell with j or k :(