Atom/Sublime like Multiple selections in Jupyter

前提是你 提交于 2019-12-21 07:38:50

问题


How can I select matching keywords in a Jupyter notebook via a keyboard shortcut? For example, in the Atom/Sublime editor I can hit cmd + D on a mac (or Ctrl + d on Windows) while the cursor is over 'var' and each time I do that the next 'var' will be highlighted. I can then type the new variable name and 'var' is replaced with whatever I typed.

var = "hello"
print(var)
print(var)

Is there an equivalent in a Jupyter notebook?


回答1:


Add custom.js to

C:\Users\username\.jupyter\custom      # for Windows and 
~/.jupyter/custom/                     # for Mac 

with content

require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
    function(sublime_keymap, cell, IPython) {
        cell.Cell.options_default.cm_config.keyMap = 'sublime';
        cell.Cell.options_default.cm_config.extraKeys["Ctrl-Enter"] = function(cm) {}
        var cells = IPython.notebook.get_cells();
        for(var cl=0; cl< cells.length ; cl++){
            cells[cl].code_mirror.setOption('keyMap', 'sublime');
            cells[cl].code_mirror.setOption("extraKeys", {
                "Ctrl-Enter": function(cm) {}
            });
        }
    } 
);

and restart jupyter. Now Ctrl+D should work like it does in Sublime.

You can see that Ctrl-Enter functionality is disabled as it would be very convenient to run current cell rather than creating new line for most users. You can choose to have that functionality by commenting that line out.

You can disable other key config that you don't want in a similar way.



来源:https://stackoverflow.com/questions/41553806/atom-sublime-like-multiple-selections-in-jupyter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!