Issue with tab size on console applications

I am having issues with tab size on vim, neovim and nano on both terminals I have (st and alacritty). On terminal text editors tabs are 8 spaces long, but if I open the same file with either sublime text, Clion or Eclipse I see the same tab as 4 spaces(which is desired). Only exception I found is in lua files, where tab size is 2 for all editors except nano. LunarVim is an outlier where tab size is always 2. If I create a file on NeoVim(not in regular Vim) then when file is saved indentation changes to 2 spaces for all editors.(Edit: Forgot I had an autocmd for this on neovim) What do I do to make it consistent? Is it possible to make it always 4 spaces?

asked Oct 1, 2023 at 16:25 15 4 4 bronze badges

Tab spacing is program independent - I'm of the mindset tabs should always be converted to spaces, as it makes for much better compatibility between programs. vim , nano , GUI text editors, etc. will all have a config setting to auto convert all tabs to spaces, which would resolve the display inconsistencies. All also have config options to set how many spaces a tab should be, and with code, four or eight is waaaay too many, resulting in an inefficient display of the code, and a ton of wasted space. If working on random machines, create terminal configs on GitHub to download and use =]

Commented Oct 2, 2023 at 11:16 These are the custom configs I use for nano ( .nanorc ) and vim ( .vimrc ) Commented Oct 2, 2023 at 11:50

8 spaces for sure are too many, but I like 4, not too sure if it is good on my 15" laptop, but on my 27" monitor it's great

Commented Oct 2, 2023 at 20:20

1 Answer 1

Terminal tabs are "always" 8 characters (positions) wide, I'd call this "hardware tabs", as it stems from the default tab stops of the typewriter ages.

"More advanced Text editors" usually have two settings; use simulated hardware tabs, or use space-fill techniques to define shorter tab-locations. What exactly to use can often be set in "Options" or "Preferences" of that text editor.

Example; Kate text editor > Menu:Settings > Configure Kate > Dialog:Editing > /Indentation\ > Indent using spaces > .

Example; nano, terminal text editor has the command line options -T, -E and -i options to define what to use and how wide tab stops should be and whether to "autoindent" (copy the whitespace from the line above the current). Ref: $ man nano

So, your "problem" editors (sublime text, Clion, Eclipse) are likely to have settings (preferences) that define their differing behavior.

C:\> type file.txt or $ cat file.txt is most likely to "always" expand TAB-characters (in the file) to 8 positions.
Ref: $ man terminfo hit / , type Tabs and Initialization , hit Enter

Oh? Not using Linux, sorry - you didn't tell!