Atom/Sublime like Multiple selections in Jupyter

后端 未结 2 1970
盖世英雄少女心
盖世英雄少女心 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:25

    The above solution worked for me, but I found that it had the undesirable effect of entering a "tab" character when I hit enter. Here is the associated GitHub issue: https://github.com/jupyter/notebook/issues/4769#issuecomment-511935127

    Per that post, I found that this solution gives the right ctrl + d behavior, and keeps tabs-as-spaces.

    require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
        function(sublime_keymap, cell, IPython) {
            // setTimeout(function(){ // uncomment line to fake race-condition
            cell.Cell.options_default.cm_config.keyMap = 'sublime';
            var cells = IPython.notebook.get_cells();
            for(var c=0; c< cells.length ; c++){
                cells[c].code_mirror.setOption('keyMap', 'sublime');
            }
            // }, 1000)// uncomment  line to fake race condition 
        } 
    );
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题