在 Jupyter 笔记本中,如何将自动缩进更改为制表符而不是 4 个空格

Var*_*nga 8 ipython jupyter jupyter-notebook

我刚开始使用 jupyter notebook。谷歌搜索没有帮助。谢谢!

更新:答案的快速摘要

在启动 ipython 文件之前在单元格中运行以下代码为我完成了任务。一个问题是我们必须每次都为每个文件运行它。

    %%javascript

    // 将设置应用到所有当前 CodeMirror 实例
    IPython.notebook.get_cells().map(
        function(c) { return c.code_mirror.options.indentWithTabs=true; }
    );

    // 确保将来创建的新 CodeMirror 实例也使用此设置
    CodeMirror.defaults.indentWithTabs=true;

Ale*_*exG 5

如果您在单元格中运行此 javascript 代码,它应该允许您插入硬标签:

%%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()
Run Code Online (Sandbox Code Playgroud)

这个对我有用。来源 = http://pirsquared.org/blog/indenting-tabs.html