Atom/Sublime like Multiple selections in Jupyter

后端 未结 2 1969
盖世英雄少女心
盖世英雄少女心 2021-02-07 05:33

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

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 06:35

    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.

提交回复
热议问题