| zedkaido.com > writing | RSS
#tabs #spaces #code #indentation
2025-12-20
Written by Zed Kaido

TABS vs SPACES

Look, at the end of the day, I don't care. vim-sleuth plug handles both heuristically and sets the appropriate settings based on the project's .editorconfig, modelines or related files in the filetree.

However and nevertheless, after having used both for over a decade, I tend to be more inclined towards using TABS for a miriad of reasons:

  1. ACCESSIBILITY: TABS let you customize indentation width to [8, 4, 3, 2, 1] or whatever you want, feel and (more importantly) NEED. Moreover, it is quite easy to set up a CMD in vim for switching TAB width with :TAB x

  2. vimrc
    vim9script
    
    def TAB(len: string = '8')
    	var n = str2nr(len)
    	execute "set tabstop=" .. n
    	execute "set shiftwidth=" .. n
    enddef
    command! -nargs=? TAB TAB()
    

  3. YOUR KEYBOARD: has a TAB key and a SPACE key. The TAB key is for HARD-TABS. The SPACE key is for SPACES. Yet, you want to use your TAB for SPACES?

  4. INDEPENDECE/PORTABILITY: A TAB is the same control character byte everywhere, as defined by ASCII (0x09) - Thus, you don't need to depend on your editor to ADD x amount of spaces when pressing <TAB> and DELETE x amount of spaces when pressing <BACKSPACE>.

  5. EASIER TO REGEX: It is trivial to target a TAB (\t|^I) through REGEX or S&R :%s/<CTRL-v><TAB>PATTERN/<CTRL-v><TAB>REPLACEMENT/gc because TABS are only used for indentation.

  6. GOLDEN RULE of TAB usage: TABS should be used for indentation. SPACES should be used for alignment. TABS should NEVER be used for alignment. SPACES should NEVER be used for indentation. (*) This guarantees code alignment for different TAB sizes:
index.html [⇥ TAB] [· SPACE]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
······content="width=device-width,
···············initial-scale=1.0">
<meta name="description"
······content="TABS for INDENTATION. SPACES for ALIGNMENT">
</head>
<body>
</form action="/submit" method="post">
<fieldset>
<legend>Choose TABS</legend>
<input type="radio"
·······id="tabs"
·······value="TABS" />
<input type="radio"
·······id="spaces"
·······value="spaces"
·······disabled />
</fieldset>
</form>
</body>
main.c [⇥ TAB] [· SPACE]
void drw_clr_create(Drw *drw,
····················Clr *dest,
····················const char *clrname)
{
if (!drw || !dest || !clrname)
return;

if (!XftColorAllocName(drw->dpy,
·······················DefaultVisual(drw->dpy, drw->screen),
·······················DefaultColormap(drw->dpy, drw->screen),
·······················clrname, dest))
die("error, cannot allocate color '%s'", clrname);
}

¯\_(ツ)_/¯ As it turns out, the answer is neither TABS nor SPACES, 'tis both.


QUICK INDENTATION Tips


  1. Regardless of what you choose, (please) use .editorconfig.
  2. Update your GitHub TAB width in Settings > Appearance, or use the ?ts=2 param to adjust TAB width on the fly, just like in this page.
  3. In INSERT Mode use <C-t>/<C-d> to add/remove indents as you type.
  4. Finally, you might find the following vim settings handy:

  5. vimrc
    set copyindent
    set listchars=tab:⇥\ ,trail:·,extends:>,precedes:<
    nnoremap <leader>tl :set list! \| :echo &list <CR>
    
OPUS HUMANUM