How to indent inline comments (end of line comments)?

I am unable to find out how to indent inline comments (i.e. comments at the end of line) in the JupyterLab text editor.

PEP8 says that inline comments should be separated by at least two spaces. The example in PEP8 shows indentation by multiple spaces:

x = x + 1                 # Compensate for border

I completely agree with this style and I think it is really good idea to indent the comments to certain tab stops so that comments on multiple lines can be aligned. The same problem is being asked about on StackOverflow:

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

Note that I am not interested in inserting a literal tab but to indent using spaces to the next indentation stop.

How can we achieve this? In usual text editors I simply press TAB the required number of times at the end of the line. In the JupyterLab text editor TAB behaves weirdly. It always indents the beginning of the line regardless the position of the cursor.

1 Like