Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do I change my nano tab to 4 spaces?

-T <#cols>, --tabsize=<#cols> For four spaces, the appropriate command would therefore be nano -ET4 .

How do I change my tab to 4 spaces?

java, then entering a { and hitting Enter indents the following line. As for tabs, there are two settings. Within Vim, type a colon and then "set tabstop=4" which will set the tabs to display as four spaces. Hit colon again and type "set expandtab" which will insert spaces for tabs.

Is tab 4 spaces or 8?

Because the default tab size in Linux console is 8 spaces, and therefore most CLI text editors in Linux also default to 8 spaces.

How do you indent on nano?

Use Alt+a to select a block, then Alt+} will indent the selected block, and Alt+{ will outdent the block.


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

Command-line flag

From man nano:

-T cols (--tabsize=cols)
    Set the size (width) of a tab to cols columns.
    The value of cols must be greater than 0. The default value is 8.
-E (--tabstospaces)
    Convert typed tabs to spaces.

For example, to set the tab size to 4, replace tabs with spaces, and edit the file "foo.txt", you would run the command:

nano -ET4 foo.txt

Config file

From man nanorc:

set tabsize n
    Use a tab size of n columns. The value of n must be greater than 0.
    The default value is 8.
set/unset tabstospaces
    Convert typed tabs to spaces.

Edit your ~/.nanorc file (create it if it does not exist), and add those commands to it. For example:

set tabsize 4
set tabstospaces

Nano will use these settings by default whenever it is launched, but command-line flags will override them.


In nano 2.2.6 the line in ~/.nanorc to do this seems to be

set tabsize 4

Setting tabspace gave me the error: 'Unknown flag "tabspace"'


Setting the tab size in nano

cd /etc
ls -a
sudo nano nanorc

enter image description here

Link: https://app.gitbook.com/@cai-dat-chrome-ubuntu-18-04/s/chuaphanloai/setting-the-tab-size-in-nano