24
  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

5
  • Could you show examples of what you have tried, include the code in your question and explain more precisely what you do not achieve ?
    – Mijamo
    Apr 1, 2016 at 9:17
  • 4
    How does this only have 5 votes so far? Is the intersection between those who care about pep8 and those who use notebooks really that small? Oct 21, 2017 at 20:48
  • I am not using notebook anymore. What should I do? What is the standard protocol to be followed in such condition on this forum? Apr 10, 2018 at 1:25
  • What are you using now, @Neeraj ?
    – ibarrond
    Dec 7, 2018 at 10:06
  • @ibarrond: I am using Pycharm Dec 8, 2018 at 12:07

5 Answers 5

13

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

3

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

2
  • Note: You'll find there are different options for Notebooks and Text; Within notebooks there are different options for markdown vs. code cells.
    – MRule
    Sep 29, 2022 at 17:26
  • In version 3.6.4 there is no settings category "Rulers" and search for "ruler" leads to NO results (this appears to be a bug since there are in fact many "Ruler" settings). You need to separately go to Notebook and Text Editor, scroll down to "Rulers", click add ruler, then specify the character width. The ruler is nearly invisible on low-color-depth monitors and you may need to adjust brightness/contrast to see it. There is no way to adjust the color or style of the rule.
    – MRule
    Jun 24 at 8:34
1

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.

1

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.

0

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'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.