Thursday, January 23, 2020

(Python) Setting nano up for Python scripting

There are much better IDEs for Python than using nano if you are doing app development. For quick hacks though nano works great. With a few tweaks it can be a much better experience.

For Python code the recommended spacing is to use:

Per the PEP: https://www.python.org/dev/peps/pep-0008/#indentation

  • Spaces are the preferred indentation method (Avoid using tabs).
  • Use 4 spaces per indentation level.
  • Limit all lines to a maximum of 79 characters (we dont fix this here)


I use nano all the time (convenience) but the default is an 8 space tab.

You can set it each time from using the nano arguments

nano -$ -clET 4 <filename.txt>

  • -$ = Enable soft line wrapping
  • -c  = Constantly show cursor position
  • -l = Show line numbers in front of text
  • -E =  Convert typed tabs to spaces
  • -T  <#cols> = Set width of a tab to #cols columns



or this can be permanently reset in the system nanorc file and just work when you launch nano:

nano /etc/nanorc

  • set tabsize 4
  • set tabstospaces
  • set constentshow
  • set linenumbers
  • set softwrap