How do I get spaces instead of tabs in nano?

31,196

Solution 1

From the nano Command Manual:

-E, --tabstospaces
Convert typed tabs to spaces.

-T <#cols>, --tabsize=<#cols>
Set the displayed tab length to #cols columns. The value of #cols must be greater than 0. The default value is 8.

For four spaces, the appropriate command would therefore be nano -ET4.

Consider creating a permanent alias.

Solution 2

Either create .nanorc in your home folder, including:

set tabsize 4
set tabstospaces

or edit the system /etc/nanorc file.

Share:
31,196

Related videos on Youtube

flo
Author by

flo

I'm a Software Developer in Berlin, Germany.

Updated on September 18, 2022

Comments

  • flo
    flo over 1 year

    I usually edit Python files with nano, so I need four spaces instead of a tab. How can I get nano to automatically insert spaces for tabs, and control how many of them it inserts?

  • theTuxRacer
    theTuxRacer about 13 years
    you could also consider editing /etc/nanorc instead of making an alias.
  • Srikanth
    Srikanth almost 12 years
    I feel like patching /etc/nanorc.... and uploading to fix this once and for all. With python3 not accepting mixed tabs&spaces this is silly to have tabs in python files in nano.