Reputation: 3084
I'd like to have a default indentation size of 2 spaces instead of 4 spaces in my Jupyter notebooks. How can I do this?
Note: this is not a duplicate of How do I change the autoindent to 2 space in IPython notebook, as that question is for (deprecated) IPython notebooks and not (current) Jupyter notebooks.
Upvotes: 6
Views: 5983
Reputation: 3084
The correct way to do this is in bpirvu's buried answer to How do I change the autoindent to 2 space in IPython notebook:
Just edit ~/.jupyter/nbconfig/notebook.json
. Here is a complete notebook.json
which includes the relevant setting:
{
"CodeCell": {
"cm_config": {
"indentUnit": 2
}
}
}
There's also a more hacky solution that's more prevalent around the web, probably because the Jupyter documentation is lacking on this topic and indentUnit
is only mentioned here: http://jupyter-notebook.readthedocs.io/en/latest/frontend_config.html. This solution is to open your browser's JavaScript console and enter
var cell = Jupyter.notebook.get_selected_cell();
var config = cell.config;
var patch = {
CodeCell:{
cm_config:{indentUnit:2}
}
}
config.update(patch)
which ends up editing ~/.jupyter/nbconfig/notebook.json
for you.
Upvotes: 11