2016-11-29 650 views
0

我剛開始使用jupyter筆記本。谷歌搜索沒有幫助。謝謝!在Jupyter筆記本中,如何將自動縮進更改爲製表符而不是4個空格

更新:答案

運行在電池下面的代碼,然後再開始一個IPython的文件得到了我做任務的快速摘要。一個問題是我們必須每次爲每個文件運行一次。

 

    %%javascript 

    // apply setting to all current CodeMirror instances 
    IPython.notebook.get_cells().map(
     function(c) { return c.code_mirror.options.indentWithTabs=true; } 
    ); 

    // make sure new CodeMirror instances created in the future also use this setting 
    CodeMirror.defaults.indentWithTabs=true; 

回答

1

如果您在單元格這段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() 

這對我的作品。來源= http://pirsquared.org/blog/indenting-tabs.html

+0

我每次打開ipynb文件時都必須這樣做嗎? –

+0

我已經嘗試把這個放在〜/ .jupyter/custom/custom.js和〜/ .ipython/profile_default/static/custom/custom.js中:放入兩個位置之後,我重新啓動了筆記本,並且仍然看到這些標籤是顯示爲空格:( –

+0

@VarunJanga你應該把這段代碼放到你當前的ipython筆記本的一個單元格中,然後運行這個單元格,並且是必須爲每個文件完成的。它不是一個完美的解決方案,而是一個很好的解決方案,完成你正在尋找的東西 – AlexG