我想在我的Jupyter笔记本中使用2个空格而不是4个空格的默认缩进大小。我怎样才能做到这一点?如何在我的Jupyter笔记本中配置缩进大小?
注意:这不是How do I change the autoindent to 2 space in IPython notebook的重复,因为该问题针对(折旧)IPython笔记本,而不是(当前)Jupyter笔记本。
我想在我的Jupyter笔记本中使用2个空格而不是4个空格的默认缩进大小。我怎样才能做到这一点?如何在我的Jupyter笔记本中配置缩进大小?
注意:这不是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
}
}
}
还有一个更哈克解决方案,它在网络上越来越普遍,可能是因为缺乏关于这一主题的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
你。
试图第二控制台溶液产生以下错误对我来说:'未捕获的类型错误:config.update不是一个函数;在:8:8;'。咩。 –
xtian