Neeraj Hanumante
Neeraj Hanumante

Reputation: 1684

ipython3 notebook vertical margin/marker line at 80 characters

  1. How to make ipython3 notebook show a vertical margin/marker line at 80 characters ?
  2. How to get i-bar location in ipython3 notebook ? (e.g. line 30 character 56)

These features assist in writing codes complying with PEP8. These features are available in Spyder.

Update 1: What I want is a vertical margin/marker line as shown in modified screenshot of the spyder. The other feature I am looking forward to is identification of location of i-bar. These two features are marked in the attached picture.

A similar solution is also okay. Modified screenshot of spyder

update 2: I did not find anything like this on the internet.

update 3: Jupyter Lab has a ruler setting (Sept 2020), details provided in the answer

Upvotes: 25

Views: 14608

Answers (5)

mosc9575
mosc9575

Reputation: 6367

Using jupyterlab version 3.3.0 the Advanced Settings Editor (Shortcut: Ctrl+,) has got a nice GUI and a ruler can be set easily under the header "Rulers".

Just click on "Add" and set the wanted number. The changes are applied immediately.

add ruler

Upvotes: 3

Neeraj Hanumante
Neeraj Hanumante

Reputation: 1684

This is Sept 2020. Version 2.2.8 of Jupyter Lab is available.

Answer 1: It provides a facility of a ruler in the Settings > Advanced Settings Editor. Answer by https://stackoverflow.com/a/55035981/6646912 gives general guidance on how to edit the settings. In particular, the following preferences can be included:

{
    "codeCellConfig": {
                        "rulers": [80],
                        "wordWrapColumn": 80,
                      },
}

Answer 2: Location of i-bar is also available in Jupyter Lab

Upvotes: 14

Aaron
Aaron

Reputation: 7454

If you only need it for a handful of documents there is always:

#< ---- 20 char ---->< ---- 20 char --->< ---- 20 char ---><9 char->

Which isn't ideal, but much faster than installing extensions and/or changing config files. The last one is 9 to account for the initial comment character.

Upvotes: 2

Nico Albers
Nico Albers

Reputation: 1696

You should have a look at the Jupyter Nbextensions. They Provide some (unofficial) community-driven extensions, also the vertical line / ruler like requested. you can find the documentation on the ruler here. I really like to other tools there too, like code prettyfiers or 2to3 converter and execution timer.

As far as I know there is no option to show the column count, but you can show line numbers when pressing l while having focus on the cell (focus doesn't equal editing, get the focus with pressing esc.

Upvotes: 1

KBN
KBN

Reputation: 153

For adding ruler in jupyter notebook, please have a look here. I haven't tried it though. Please let me know if this worked.

For the ibar, line numbers can be achieved - press Esc (or click on the left side of the cell where were see In [ ]: to enable the command mode and click letter 'l'.

Upvotes: 0

Related Questions