How to make the tab character 4 spaces instead of 8 spaces in nano?

Fallen Satan picture Fallen Satan · Jun 24, 2012 · Viewed 105.3k times · Source

When I press TAB in nano editor, the cursor will jump with 8 spaces like this:

def square(x):
        return x * x
def cube(y):
        return y * y * y

how can I set the tab stop width to 4 spaces to display like this:

def square(x):
    return x * x
def cube(y):
    return y * y * y

Answer

Sven Rojek picture Sven Rojek · Mar 12, 2013

If you use nano with a language like python (as in your example) it's also a good idea to convert tabs to spaces.

Edit your ~/.nanorc file (or create it) and add:

set tabsize 4
set tabstospaces

If you already got a file with tabs and want to convert them to spaces i recommend the expandcommand (shell):

expand -4 input.py > output.py