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

Customize keymaps - comment | uncomment toggle #3753

Open
rezaffm opened this issue Jul 12, 2018 · 11 comments
Open

Customize keymaps - comment | uncomment toggle #3753

rezaffm opened this issue Jul 12, 2018 · 11 comments

Comments

@rezaffm
Copy link

rezaffm commented Jul 12, 2018

Well, I am getting a bit frustrated. I tried to unbind the key for commenting in edit mode following the instructions that are given here: http://jupyter-notebook.readthedocs.io/en/stable/extending/keymaps.html - but the unbinding never took place.

Consequently, also the re-binding, for instance to "Ctrl-7" never worked as well (German keyboard).
So could maybe someone please provide an example configuration or tell me whether this is unexpected behavior or a case of "uts" (user to stupid)?

I ve been playing around with this for a while now and cd not solve it.

@takluyver
Copy link
Member

Unfortunately there are two different shortcut systems in action - Jupyter's own (which that doc explains how to configure), and Codemirror's. Codemirror is the text editor component we use for cells. So most of the editing shortcuts are caught by Codemirror's shortcut system.

@rezaffm
Copy link
Author

rezaffm commented Jul 12, 2018

Is there any "way around" or should someone actually go and use the extension to modify keyshortcuts?

@takluyver
Copy link
Member

There is some way around, I think, but I can never remember exactly what you need to do. Search for cm_config in examples and be prepared for some trial and error, because I think the ways to do it have changed over the years.

@rezaffm
Copy link
Author

rezaffm commented Jul 12, 2018

Well, I think I do not have to much luck with these shortcuts: ipython-contrib/jupyter_contrib_nbextensions#1321

@rezaffm
Copy link
Author

rezaffm commented Jul 13, 2018

I searched through google and fine some "tutorials" to change the keyboard:

However, they all do not work. Searching the CodeMirror-Side I found the "keyMap" and "extraKeys" options that you could you during the instantiation of the editor (havent tried it yet). Looking into the addons of CodeMirror (comment.js), they toggleComment-Function is still there (same name). In the keymap e.g for instance it is called: { "Ctrl-/": "toggleCommentIndented" }

I might be thinking to easy, but the whole issue for None-US keyboards could then be solved by adding an "extraKey", for instance: extraKey = {'Ctrl+Shift+7': "toggleCommentIndented}.

How can you access CodeMirror the easierst way? Could you put me on the right track here? Should someone create a custom.js and access codemirror there?

@rezaffm
Copy link
Author

rezaffm commented Jul 13, 2018

I ve been playing around, while I found out that the toggleComment is here:

Jupyter.Cell.options_default.cm_config.extraKeys

It still has no effect, whether I change the key in the console or in a config.js File.

What am I missing?

@rezaffm
Copy link
Author

rezaffm commented Jul 13, 2018

Well, so changing anything on the Cell object had no effect. The only thig that worked finally was the following (custom.js in .jupyter/custom folder):

define([
'codemirror/lib/codemirror',
],
function(CodeMirror) {
CodeMirror.keyMap.pcDefault["Ctrl-7"] = "toggleComment"
}
);

This toggles lines no by using Ctrl and 7.

@phj6688
Copy link

phj6688 commented Feb 11, 2020

I've the same problem!!
its annoying

@jeanmonet
Copy link

Any chance of getting this to be part of a configurable option?

@AlexYoOS
Copy link

I know there is a way to manually write commands in a .js file in the jupyter notebook installation, but also editing jupyter notebook shortcuts from the shortcut menu actually works when following this strict set of rules, whereafter the notebook must be restarted:
Screenshot 2021-01-14 at 09 38 07

What however is not written in there, is that some keys seem to be exempt from functionality, e.g. if you use ssin a key combination, the key combination is added, but actually does not work

@Createdd
Copy link

I solved it like I described here: https://stackoverflow.com/a/71480779/7056765

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

No branches or pull requests

6 participants