This is a collection of various keyboard shortcuts that can make your life easier when using the atom editor with the hydrogen connection to a jupyter kernel.
These have been tested on my machine with Atom 1.32.1
and Ubuntu.
If there are differences across operating systems, or they require specific packages, please point it out.
-
Shift + Ctrl + p
open the command shell. From here one can access all the more advanced functions. it will also show the current keyboard shortcut for the chosen command, if present. can do partial search, so it will find commands based on keyword in the middle of the commands themselves (for example, the
Hydrogen: Add Watch
can be found just withwatch
) -
Ctrl + , comma
open the
Settings
tab -
Ctrl + / slash (on an italian keyboad is Ctrl + shift + 7 )
toggle comment of the code
-
Ctrl + shift + m
toggle the preview for markdown files. (requires the
markdown-preview
extension) -
Alt + shift + T
toggle the todo list as a side panel (requires the
todo-show
extension)
bookmarks allow you to quickly explore your code and go back and forth between different sections
-
Ctrl + shift + F2
add or remove a bookmark to a line
-
F2 and Shift + F2
move to the next (or previous) bookmark in the current file
-
Ctrl + F2
list the current bookmarks and allow to jump to the chosen one. Can see the bookmarks in all the files you have opened.
it will select multiple copies of the same string. It is great for a mass rename of a variable or a function in a file.
if you move the cursor after the selection, you will get multiple cursors. This is very useful to change the arguments for all the calls of a given function.
-
Ctrl + d
select the current object, if selected find the next
-
Alt + F3
finds and select all
-
Ctrl + k and then Ctrl + d
skip the selection to the next one
-
Ctrl + u
undo the last selection
-
Shift + Alt + ↑ up arrow and Shift + Alt + ↓ down arrow
create multiple cursors above and below the current one. this is very useful to modify several consecutive lines
-
Alt + ↑ up arrow and Alt + ↓ down arrow
select (or deselect) the higher level of syntax block from the current selection. for example, from the cursor it will select the variable name it is placed on, then the function call list of arguments, then the whole function, and so on
-
Ctrl + Alt + , comma
select all the content inside the current function call.
-
Ctrl + r
finds all the symbols defined in the current files (functions, variables, etc...)
-
Ctrl + ↑ up arrow and Ctrl + ↓ down arrow
move the current line above or below
-
Shift + Alt + ↑ up arrow and Shift + Alt + ↓ down arrow
put multiple cursors above or below the current one. one can return to a single cursor pressing Esc
-
Ctrl + g
goes to a specific line
-
Ctrl + l
select the whole line the cursor is currently on
-
Ctrl + left arrow or right arrow
skip to the previous or next word. using Alt instead of Ctrl allows a more fine-grained control. combined with Shift can be used to select text.
-
Ctrl + Del or Backspace
delete to the end (or the beginning) of the current word.
-
Shift + Home or End
Select the text to the start of the line or the the end of it
-
Ctrl + Home or End
go the the beginning or the end of the file
-
Shift + Enter
execute a selection or the current line in hydrogen, go to the next one
-
Ctrl + Enter
execute a selection or the current line in hydrogen, stays on the current one
-
Shift + Alt + Enter
Execute the current block and go to the next one (blocks are delimited by
# %%
) -
Ctrl + Alt + Enter
Execute the current block and remains in it (blocks are delimited by
# %%
) -
Alt + i
open the inline help of hydrogen with the help of the function or object that the cursor is corrently residing on
-
from the command shell: search for
Hydrogen: Add Watch
create a new watch. Watches allow for small snippets of code to be execute whenever you launch a new command. They can be useful to check the results of a plot when you modify the way data are processed.
-
from the command shell: search for
Hydrogen Python: toggle variable explorer
show as a side tab a simple variable explorer similar to those of spyder and matlab (but less powerful)
-
from the command shell: search for
Hydrogen: toggle output area
show a new area on the side that display the results of the executed commands instead of showing them inline. this is very useful to select text from the output, as the inline version does not allow text selection.
for this kind of explorative work, there are few useful snippets to be used
-
library
pdir2
is a drop-in replacement for the default dir function, with some more goodies. import it with
import pdir as dir
and then put a watch withdir().public
to have a list of all the functions and modules and a short help
-
IPython JSON display
useful to display dictionaries and lists of simple objects in an interactive way. import it with
from IPython.display import JSON
and then use it withdata = [1, 2, {'a':1}] JSON(data, expanded=True)
-
pandas styles
these are useful when doing data exploration. instead of just displaing the basic dataframe, with this one can have a rich display. one can access a dataframe style with
.style
, and then create a rich display using pre-defined functions or extending them as you needd = pd.DataFrame(plt.randn(5, 3)) d[0] = plt.nan d.style d.style.highlight_null() d.style.highlight_null().highlight_max() d.style.highlight_max(color='darkorange', axis=1) d.style.background_gradient()
you can have the whole list with
dir(d.style).public.methods
-
pandas_profiling
generates reports on a dataframe, including statistics, correlations, etc... Can be installed with
conda install pandas_profiling
.import pandas_profiling df = pd.DataFrame(plt.randn(500, 3)) pandas_profiling.ProfileReport(df)
a similar library is
pivottablejs
, but only works in jupyter notebooks, so I haven't tested it. -
search stackoverflow for code snippets
requires the package
ask-stack
. typingask stack
in the command prompt will open a search box that will then return a series of replies from stackoverflow that can be explored directly in the sidebar. -
special character variables
ipython allow to replace special letters name with the proper representation with a ⇥ Tab. For example, it can replace
\alpha
withα
. Atom is able to do it by itself, but I don't remember from which version. This is useful to write expressive formulas, but should be used sparingly as it makes it hard to edit for someone that does not have a similar tool. it is possible to insert letter modifiers as well, such as hat, dot and so on. to make it acceptable to python, first should be the letter, than the modifier, such asa\hat
forâ
. This can make the code difficult to read with smaller fonts, so beware. Only the unicode letters can be used, so you can't have a cat face😺
for a variable, but you can have it as dictionary key if you want the world to burn. -
display online math
from IPython.display import Math formula = r'i\hbar \frac{dA}{dt}~=~[A(t),H(t)]+i\hbar \frac{\partial A}{\partial t}.' Math(formula)
-
code block descriptions
dividing the script in code blocks is useful to keep the code nicely sorted. It is even better to put a docstring for each block to make clear what the block is about. one simple way is to put a multiline string at the beginning of it. To avoid repeating the docstring when you execute the script line by line, just put a semicolon after it.
""" docstring """;
one more fancy way to do it is to import the markdown display of ipython and wrapping the docstring with it. it will display it, and if you fold the code of the markdown, you just get the nice visualization without the raw string.
from IPython.display import Markdown Markdown("""# test * riga 1 * riga 2 """)
-
artificial code blocks
sometimes it is useful to collect a bunch of code in a block to be executed all together, or disables all together. One way of doing it that works reasonably well without relying on the code block convetion is to use an if statement with a short descriptive string.
if "print something to screen": a = 3 print(a)
if you want to skip the whole block all together you can just interpose a
not
between the if and the description string.if not "execute my awesome code that is useless now": pass
-
ipython-sql
to exectute SQL calls inside your scriptload it with
%load_ext sql
then you can run SQL commands as a block
%%sql sqlite:// CREATE TABLE writer (first_name, last_name, year_of_death); INSERT INTO writer VALUES ('William', 'Shakespeare', 1616); INSERT INTO writer VALUES ('Bertold', 'Brecht', 1956);
or as a single instruction
a = %sql select * from writer a.DataFrame() # to get it as a pandas data frame
it can also do dinamic binding to existing variables:
state='FINISHED' %sql SELECT :state as "bind_variable"
-
cython
(included in the cython package)allow to magically compile and import cython functions for extra performance
%load_ext cython
then declare and execute a cython block
%%cython cpdef myfunction(int a, int b): return a+b
if it runs successfully, it will import the function in the current namespace
>>> myfunction(4, 5) 9
-
file-icons
for pretty icons on the file browser to help navigating -
highlight-selected
show all the locations of the string that is highlighted -
minimap
and to have a side bar with a bird-eye view of the source code.it does have several plugins that can be installed (and activated and deactivated at will from the config icon that appears if you hover the mouse over the minimap)
-
minimap-bookmarks
andminimap-highlight-selected
display in the minimap the selected text and the bookmarks
-
minimap-titles
use the command Ctrl + shift + ⌫ Del to replace the selected text with ASCII graphics. this allow to generate titles readable in the minimap. if you apply to the word
text
, you obtain:████████ ███████ ██ ██ ████████ ██ ██ ██ ██ ██ ██ █████ ███ ██ ██ ██ ██ ██ ██ ██ ███████ ██ ██ ██
-
minimap-codeglance
codeglance helps preview the code from the minimap and is very useful, but the default graphics can be improved. I would suggest the following style. in the file
~/.atom/styles.less
, adding:minimap-codeglance { box-shadow: 0 0 40px rgba(127, 127, 127, 1); }
-
-
todo-show
to have a side bar with the TODOs and NOTEs for the current code -
teletype
to collaboatively write code -
simple-drag-drop-text
to move around selected text with the mouse -
platformio-ide-terminal
include a simple terminal in the shell. might need to setsource ~/.bashrc
in the config to see the path properly -
color-picker
use Ctrl + Alt + C to open up a color explorer and generate the string with the appropriate color. Very useful when plotting stuff. -
tablr
allows to visualize and edit csv-like files in the editorthe repository linked in atom is not working anymore, but a working fork can be installed using:
apm install https://github.com/mfripp/atom-tablr.git
-
project-manager
allows to switch easily between different projects. it relies completely on the command prompt. -
NOT WORKING (in
hydrogen-python
setextend executable code
)this makes sure that when you select a block to run such a an
if
statement, it runs the corresponding else as well -
NOT WORKING (
data-explorer
)this should allow interactive plotting of a dataframe