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

nanorc
vim set tab to 4 spaces
nano auto indent
nano convert spaces to tabs
nano show line numbers
nano utf-8
inconsistent use of tabs and spaces in indentation nano
nano go to line

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

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

Setting the tab size in nano, Either create .nanorc in your home folder, including: set tabsize 4 set tabstospaces. or edit the system /etc/nanorc file. 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.

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.

command line - How do I get spaces instead of tabs in nano?, The nanorc file contains the default settings for nano, a small and friendly editor. make it wrap lines at blank characters (tabs and spaces) instead of always at the edge of The default pair for a UTF-8 locale is "»⋅", and for other locales ">."​. By default the tab size in nano is 8 spaces, but it is possible to change the tab size either on the command line, in the system wide configuration file, or in a user specific configuration file. From the command line you would do this: nano -T 4 /path/to/fileORnano --tabsize 4 /path/to/file. It is more convenient to save the setting into a configuration file to save you having to type this on the command line all the time.

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"'

nanorc, Many Linux system administrators use Nano to do basic editing of Linux a .​nanorc file in the HOME directory of the user you want to configure Nano for. On Nano text editor, the default tab size is 8 characters wide. If you replace tabs with specific numbers of spaces, then you won't have to face this problem again. So an example — let’s say you want to convert any instance of 8 spaces to a tab character. Here is the command stack: control-W (search) control-R (replace) hit space 8 times, then hit enter. alt-shift-V (verbatim input) hit the tab key, hit enter. Proceed as normal.

For future viewers, there is a line in my /etc/nanorc file close to line 153 that says "set tabsize 8". The word might need to be tabsize instead of tabspace. After I replaced 8 with 4 and uncommented the line, it solved my problem.

Configuring Nano Text Editor with nanorc – Linux Hint, To define the tab size (let's say 4 characters wide) in Nano text editor, use … Today we've published the PyCharm 3.4.1 RC build 135.1049, which is already be one space off, it's difficult to tell by simple inspection if there are 7 or 8 spaces… Set on tab Editor: Tab width: 4 spaces, Insert spaces instead of tabs, Enable  How to make the tab character 4 spaces instead of 8 spaces in nano? (3) 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.

Setting the tab size in nano

cd /etc
ls -a
sudo nano nanorc

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

pycharm set tab to 4 spaces, Inserting TAB in nano works, but the tabs are spaces, you can go I have to open a gui text editor to insert tabs, then only the tabs are In some editors they default to 8 spaces, more commonly in code that follows the K&R standards for By the way, all the cool kids are using Micro instead of Nano these  Most IDE's may insert automatically 4 spaces when hitting the tab key, but usually they remove just 1 space when hitting backspace (un-indent operation is still accessible as shift-tab, but that's a two key combination) or you use the mouse to click in the middle of the indentation and delete one character.

(terminal) nano converts TAB to ordinary SPACE, Set on tab Editor: Tab width: 4 spaces, Insert spaces instead of tabs, Enable This PyCharm plugin brings a variety of keyboard shortcuts to make coding quickly, To follow PEP-8 standar, for identation (tabs) it's recommended 4 spaces, not 8 To define the tab size (let's say 4 characters wide) in Nano text editor, use … Go to the Preferences menu command under menu Settings, and select Language Menu/Tab Settings, depending on your version. Earlier versions use Tab Settings. Later versions use Language. Click the Replace with space check box.

pycharm set tab to 4 spaces, Tabs and spaces are two different characters which are rendered as as much space as 8 spaces, some show it as occupying width of 4 and some 2, Though it's not really possible to do this when editing someone else's  [ Conversion of typed tabs to spaces disabled ] or [ Conversion of typed tabs to spaces enabled ] respectively. Another way (only for nano 1.3.1 or newer): You can insert a literal tab if you enter Verbatim Input mode with Shift+Alt+V (or Meta+V). If you then type Tab, nano will insert a literal tab character, irrespective of your .nanorc settings

What is the “inconsistent use of tabs and spaces in indentation” error , Set on tab Editor: Tab width: 4 spaces, Insert spaces instead of tabs, Enable automatic On Nano text editor, the default tab size is 8 characters wide. This PyCharm plugin brings a variety of keyboard shortcuts to make coding quickly, less  not possible to have problem like using 7 spaces instead of 8. 4) not need to agree how many tabs to use: tabs is always one, spaces are usually 4, but some prefer 2 spaces. 5) it’s FASTER to tab than to 4-space. 6) In a file with TAB, one can know which character is used for indentation and which one for spacing. —

Comments
  • Nano is a pretty basic editor. There's a good chance it just doesn't support this.
  • umm not only in nano, but it also indent by 8 spaces when I use python interpreter in Terminal.
  • This is answered on SuperUser, and should be closed as duplicate: superuser.com/questions/110421/tab-character-width-in-terminal
  • @millimoose, changing the tab stops in the terminal doesn't affect nano. This question should be specifically about nano or about setting the tab stops for Python, but not about both and not about interactively setting the tab stops with the tab command, which doesn't affect all programs.
  • I'm using mint and when I set tabsize from 8 to 4 in /etc/nanorc and go back to the file, I'm still getting 8 spaces in the tab, I even tried to copy that nanorc file to ~/. but that doesn't work, closed and reopened terminal, but still I can't get 4 spaces on the tab unless I use nano -T4. Thanks
  • @Alex double check that your file starts with a dot .nanorc not nanorc. This must be placed in your users home-directory, i.e. /home/your-username/.nanorc.
  • Thanks, I ended up creating another .nanorc different from the one in /etc, placed it in the home dir and that worked. This are the only 3 lines I included in the new .nanorc for anyone interested: set nowrap, set tabsize 4 and set tabstospaces
  • If this is your toy, you can make this change available system wide, just edit the global file /etc/nanorc. There are a few other options there that you may enjoy.
  • Hi @Alexey . This Linux Shell command works for all files, but make sure to specify another output-file, otherwise your file will be emptied.
  • umm... i can't find the .nanorc file in ~/ directory
  • Ok never mind. I find nanorc in /etc directory. thanks though
  • @FallenSatan, generally you should avoid editing /etc/nanorc, unless you need to perform system-wide customizations. Create ~/.nanorc if it doesn't already exist and put your customizations there.
  • Note that in the above answer you need to add the line "set tabsize 4", not "set tabspace 4"
  • sudo nano will not take ~/.nanorc for an obvious reason; so the command-line flag is a more practical solution to the problem.
  • Link is dead, have you got an alternative explanation?