我想在我的 Jupyter 笔记本中使用 2 个空格而不是 4 个空格的默认缩进大小。我怎样才能做到这一点?
注意:这不是 How do I change the autoindent to 2 space in IPython notebook 的副本,因为该问题针对(已弃用)IPython 笔记本而不是(当前)Jupyter 笔记本。
最佳答案
正确的方法是在 bpirvu 对 How do I change the autoindent to 2 space in IPython notebook 的隐藏答案中:
只需编辑 ~/.jupyter/nbconfig/notebook.json
。这是一个完整的 notebook.json
,其中包括相关设置:
{
"CodeCell": {
"cm_config": {
"indentUnit": 2
}
}
}
还有一个在网络上更流行的更hacky 的解决方案,可能是因为 Jupyter 文档缺乏关于此主题的内容,而
indentUnit
仅在此处提及: http://jupyter-notebook.readthedocs.io/en/latest/frontend_config.html 。此解决方案是打开浏览器的 JavaScript 控制台并输入var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
CodeCell:{
cm_config:{indentUnit:2}
}
}
config.update(patch)
最终会为您编辑
~/.jupyter/nbconfig/notebook.json
。
关于jupyter-notebook - 如何在我的 Jupyter 笔记本中配置缩进大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40800349/