Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Atom/Sublime like Multiple selections in Jupyter

Tags:

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?

like image 994
RancheroBeans Avatar asked Jan 09 '17 17:01

RancheroBeans


People also ask

How do you select similar words in Jupyter notebook?

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.

What does %% capture do in Jupyter?

Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable. By default, %%capture discards these streams. This is a simple way to suppress unwanted output.


1 Answers

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.

enter image description here

like image 152
Saravanabalagi Ramachandran Avatar answered Sep 21 '22 06:09

Saravanabalagi Ramachandran