I find that developing functions in IPython notebook allows me to work quickly. When I'm happy with the results I copy-paste to a file. The autoindent is 4 spaces, but the coding style for indentation at my company is 2 spaces. How do I change the autoindent to 2 spaces?
Implement Auto-Indent Lines ( Ctrl + Alt + I ) and Reformat Code ( Ctrl + Alt + L ) for Python code cells in Jupyter notebook source code representation.
ctrl+o. If you type ctrl+o, you should be able to add additional lines to the input to run them simultaneously.
The official documentation has an example answering this specific question. This worked for me with IPython 4.
Summary: Paste the following into your browser's javascript console
var cell = Jupyter.notebook.get_selected_cell(); var config = cell.config; var patch = { CodeCell:{ cm_config:{indentUnit:2} } } config.update(patch)
The setting is persisted. You can roll back by exchanging : 2
for : null
.
From the official documentation for CodeMirror Code Cells:
b
snippet:
var cell = Jupyter.notebook.get_selected_cell(); var config = cell.config; var patch = { CodeCell:{ cm_config:{indentUnit:2} } } config.update(patch)
F5
This will fix it permanently. I assume this works only on recent versions, not sure though!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With