Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a literal tab instead of auto-completing in Jupyter?

It is easy to indent a whole line.

  1. Just highlight the whole line and press Tab

  2. Go to the start of the line and press Tab

  3. Click anywhere in the line and press Ctrl + ]

Now the problem is how to insert indent in the middle of the line.

And also, how to indent at the end of the line.

Example usage scenario:

# Hyperparameters
LENGTH = 10 # length of foo
TEMP = 20 # temperature of bar
IV = 99.99 # induction variability of foo bar

Concretely, we want:

# Hyperparameters
LENGTH = 10    # length of foo
TEMP = 20      # temperature of bar
IV = 99.99     # induction variability of foo bar

Or even better (in some cases):

# Hyperparameters
LENGTH = 10        # length of foo
TEMP   = 20        # temperature of bar
IV     = 99.99     # induction variability of foo bar
  1. Note that by pressing the Tab button however, we are actually calling auto-complete instead of indenting.
  2. Of course we can always manual align them by using spacebar, but then we will have to do this every time we tune the hyperparameters.

So, how to indent instead of auto-completing in Jupyter?

P.S. Yes, I am aware of print("\t"), copying the output and pasting the indent. But that is not desirable.

like image 940
Sayyora Avatar asked Mar 26 '18 17:03

Sayyora


1 Answers

One alternative would be to use the Alt keyboard sequence.
In this case it would be Alt + 09. It is about as short as one could hope for.

For this to work you need a numpad on your keyboard, as the top row of numbers on the keyboard does not work to produce Alt keyboard sequences.

However, this does leave rather ugly arrows in place of the tab, which seems to be the way Jupyter Notebooks displays tab characters.

like image 165
Anders Avatar answered Sep 30 '22 10:09

Anders