question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using tabs in Jupyter notebook cells (re-open #10423)

See original GitHub issue
%%file Makefile
hello: hello.c
    cc -o hello hello.c

is why we need TABs instead of spaces: make assumes tabs, and ONLY tabs, as valid separators and crashes out if this is not done.

I use workaround

%%bash
echo    "hello: hello.c" > Makefile
echo -e "\tcc -o hello hello.c" >> Makefile

but in a teaching environment - where I use jupyter notebook, this is inadequate.

I added editor-tabs nbextension to the Home, and disabled “disable configuration for nbextensions without explicit compatibility” check mark in the console, but it did not change the behaviour of the notebook, even after a kernel restart. This functionality is desperately needed in %%file cells, and TAB-as-completion is unnecessary in those.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
esternincommented, Jan 25, 2018

I did not realize ipython is still a thing, I assumed jupyter was a rebrand/replacement.

But I also see that your comment betrays a continuous misunderstanding, so perhaps I better elaborate. Every time an issue of tabs comes up, everyone assumes it’s about the automatic indentation style. It is not! - and in fact I personally prefer and always use spaces, not tabs, to indent code. But the ability to enter a TAB character when desired must be available, as other programs and environments may require it (Makefile being one example).

So, for example, including somewhere in the notebook this:

%%javascript

IPython.tab_as_tab_everywhere = function(use_tabs) {
    if (use_tabs === undefined) {
        use_tabs = true; 
    }

    // apply setting to all current CodeMirror instances
    IPython.notebook.get_cells().map(
        function(c) {  return c.code_mirror.options.indentWithTabs=use_tabs;  }
    );
    // make sure new CodeMirror instances created in the future also use this setting
    CodeMirror.defaults.indentWithTabs=use_tabs;

    };

IPython.tab_as_tab_everywhere()

converts ALL cells to tabs. This is a poor solution, distracts from the flow of the notebook, and not at all what I am asking for.

I would like to have, say, Alt-TAB or Ctl-TAB generate a raw tab and not be replaced with 4 spaces, but only when I need that. It’s not even a per-cell control, it’s just one special character.

Is there an equivalent to vi’s Ctl-v entry mode in ipython/Jupyter/jupyterlab (what is that? and how is it different from jupyter?).

0reactions
esternincommented, May 28, 2020

This reminds me: I never thanked @Carreau for a detailed and thoughtful workaround, a tour de force. Thank you!

But lust like @dturaev I adopted the two-click (left button select, middle button paste) solution to entering the TAB characters, for those rare occasions I need them.

I would still welcome the vi-inspired Ctl-V option (for verbatim) one-keystroke prefix (no mode switching, just one composite character), if it ever makes it into the interface. There is no way I can suggest any of the approaches discussed here to a class of novice users, where I use jupyter notebooks, they would be overwhelmed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using tabs in Jupyter notebook cells #10423 - GitHub
I would like to be able to use tabs in Jupyter Notebook cells. It is currently not possible as far as I know...
Read more >
How to reopen Jupyter notebook if I closed the tab?
Select the Running Tab (as mentioned by @Quang Hoang). ... in the Jupyter terminal window (also providing you with the direct notebook url):....
Read more >
Optimizing Jupyter Notebook: Tips, Tricks, and nbextensions
Shortcuts · Esc take you into command mode · Tab code completion or indent · Shift + Tab tooltip · Ctrl + ]...
Read more >
Jupyter Notebook Quick Guide
In the Jupyter notebook window, under the “Files” tab you'll see a file structure. You will navigate through this to get to the...
Read more >
Jupyter Notebook 6.5.2 documentation - Read the Docs
Code cells . A code cell allows you to edit and write new code, with full syntax highlighting and tab completion. The programming...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found