jwkvam/jupyterlab-vim

Add comment/uncomment bindings

jrwrigh opened this issue · 11 comments

This might be more broadly addressed with custom mappings/bindings, but adding comment/uncomment bindings would be super useful. Somehing along the lines of tpope's commentary which uses gc as the binding for commenting.

Yes! CMD + / almost works (on a mac), but it puts the # at the beginning of the line rather than where the indentation starts, so I end up manually adding # characters. I would love a commentary emulator.

Question to the fellow Windows users ==> does Ctrl + / work for you? I am firing jupyter lab from a WSL-bash on a Windows machine, and have never got the commenting shortcut to work. All else are working just as nicely as they should have been.

About my configuration: I have been compiling the jupyterlab-vim locally, with only two additional key-bindings as the following. <c-[> to exit insert mode, while in a cell; and <c-]> to pop out of cell-editing mode. I don't see these settings to block <c-/> for commenting.

        commands.addKeyBinding({
            selector: '.jp-Notebook.jp-mod-editMode',
            keys: ['Ctrl ['],
            command: 'leave-insert-mode'
        });
        commands.addKeyBinding({
            selector: '.jp-Notebook.jp-mod-editMode',
            keys: ['Ctrl ]'],
            command: 'notebook:enter-command-mode'
        });

I downloaded the local copy some time in Januray, 2019. So, it should be still up to date as of this repo. My Jupyter Lab version is 0.35.4. Please advise if there is other diagnostic info that I can provide here.


Updates a few months later

In short, there is no need for me to run the custom build with the two mappings. <c-[> turns out to be redundant and <c-]> has been implemented as Shift + ESC by default.

While not documented in the ReadMe, <c-[> is mapped, by default, to escape from Insert mode and enter Normal mode in the cell. @jrwrigh pointed this out back in April 2019.
Further, Shift + Escape is mapped to the native Jupyter command "Enter Command Mode". If one shall desire additional key-bindings to replication Shift+Escape, AutoHotKey will come handy:

; This autohotkey script shall find the Jupyter windows running from Firefox/Chrome
GroupAdd , JupyterLab       , JupyterLab - Mozilla Firefox 
GroupAdd , JupyterLab       , JupyterLab - Vimperator
GroupAdd , JupyterLab       , JupyterLab - Google Chrome 
GroupAdd , JupyterLab       , JupyterLab ahk_exe chrome.exe
return
#IfWinActive ahk_group JupyterLab
    ; Here, we let Ctrl + ] to send Shift+ESC.
    ^]:: send +{ESC}
#IfWinActive

To conclude, I no longer need to run the custom build for jupyterlab_vim anymore.

Ctrl + / works for me, but I'm not running it through WSL.

On the <c-[> shortcut you've added, the plugin already has that functionality. That's what I use normally to exit INSERT mode.

@jrwrigh Just to confirm: you are using Windows machine? I have also tried to disable jupyterlab-vim, but nothing changes: Ctrl + / still got me nothing.

Plus, I did not find a proper command: clause that I can use to "hard-assign" Ctrl +/ to serve the role of toggling the comments.

Looking forward to a gc implementation as well.

Yes, I'm using Windows 10 OS.

Anaconda

Update on using Ctrl + / for commenting

As mentioned by DreamFlasher's comment in this stack overflow post, the slash symbol (/) should be interpreted as the slash symbol from the Numpad!!!

On my Windows machine, I added the following mapping to tune the normal Ctrl + / key-press into the real thing: Ctrl + Numpad-Slash.

; I used a program called AutoHotKey
; Section that declares the `ahk_group JupyterLab`: this shall capture all cases where I may be using Jupyter
SetTitleMatchMode, 2
GroupAdd , JupyterLab       , JupyterLab - Mozilla Firefox 
GroupAdd , JupyterLab       , JupyterLab - Vimperator
GroupAdd , JupyterLab       , JupyterLab - Google Chrome 
GroupAdd , JupyterLab       , JupyterLab ahk_exe chrome.exe
return


; The simple mapping, along with other things that emulate Vim's fundamental actions.
#IfWinActive ahk_group JupyterLab
    ^/:: send ^{NumpadDiv}
    ^w::Send ^+{Left}{BS}
    ^h::Send {BS}
return

Hi all.

If I were to add my own vim bindings how would I do that?

@CrashLaker You shall find a relevant discussion in #17.

Thank you!! @llinfeng