Hydrogen provides a selection of commands for running code. Press ⌘-⇧-P (On Windows press ctrl-⇧-P instead) to open the Command Palette and type "hydrogen" and they will come up.
There are two ways to tell Hydrogen which code in your file to run.
- Selected code: If you have code selected when you hit Run, Hydrogen will run exactly that code.
Current block: With no code selected, Hydrogen will try to find the complete block that's on or before the current line.
If the line you're on is already a complete expression (like
s = "abracadabra"), Hydrogen will run just that line.
If the line you're on is the start of a block like a
forloop, Hydrogen will run the whole block.
If the line you're on is blank, Hydrogen will run the first block above that line.
It's easiest to see these interactions visually:
"Hydrogen: Run And Move Down" will run the code as described above and move the cursor to the next executable line.
If your code starts getting cluttered up with results, run "Hydrogen: Clear Results" to remove them all at once.
"Hydrogen: Run Cell"
A "code cell" is a block of lines to be executed at once. You can define them using inline comments. Hydrogen supports a
multitude of ways to define cells. Pick the one you like best.
The following is an example for
python but it will work in any language, just replace
# with the comment symbol for your desired language:
When you place the cursor inside a cell and hit "Hydrogen: Run Cell", Hydrogen will execute this cell. The command "Hydrogen: Run Cell And Move Down" will move the cursor to the next cell after execution.
The addition of these cell markers also allows you to export your text file as a Jupyter Notebook file. See Notebook Export for more detail.
"Hydrogen: Run All" and "Hydrogen: Run All Above"
These commands will run all code inside the editor or all code above the cursor.
"Hydrogen: Toggle Output Area"
An external output area can be used to display output instead of the inline result view. The output can be displayed either in a scrolling view or a sliding history.
"Hydrogen: Clear Result"
Remove results at current cursor line or current lines within a selection.
"Hydrogen: Toggle Watches"
After you've run some code with Hydrogen, you can use the "Hydrogen: Toggle Watches" command from the Command Palette to open the watch expression sidebar. Whatever code you write in watch expressions will be re-run after each time you send that kernel any other code.
IMPORTANT: Be careful what you put in your watch expressions. If you write code that mutates state in a watch expression, that code will get run after every execute command and likely result in some extremely confusing bugs.
You can re-run the watch expressions by using the normal run shortcut (⌘-↩ or ctrl-↩ in Windows by default) inside a watch expression's edit field.
Receive completions from the running kernel:
"Hydrogen: Toggle Inspector"
You can use the "Hydrogen: Toggle Inspector" command from the Command Palette to get metadata from the kernel about the object under the cursor.
"Hydrogen: Interrupt Kernel", "Hydrogen: Restart Kernel" and "Hydrogen-Shutdown Kernel"
Sometimes things go wrong. Maybe you've written an infinite loop, maybe the kernel has crashed, or maybe you just want to clear the kernel's namespace. Use the Command Palette to interrupt (think Ctrl-C in a REPL), restart or shutdown the kernel.
You can also invoke these commands by clicking on the kernel status in the status bar. It looks like this:
"Hydrogen: Toggle Kernel Monitor"
You can open the kernel monitor via "Hydrogen: Toggle Kernel Monitor" and monitor various information about all running kernels like kernel status, execution count:
Additionally you can interrupt/restart/shutdown a kernel via clicking icon in the
Managements column, and jump to a file by clicking link in the
Multiple kernels inside one rich document
If you are working in a markup file that supports highlighted code blocks, we can handle multiple kernels per file. This way you can write your documentation, readme or paper together with your code while retaining the interactivity of Hydrogen.