How to insert a literal tab instead of auto-comple

2020-07-06 05:19发布

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.

1条回答
家丑人穷心不美
2楼-- · 2020-07-06 05:50

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.

查看更多
登录 后发表回答