r/ProgrammerHumor • • 12d ago

Meme formatsWithSuperiorityComplex

Post image
3.0k Upvotes

403 comments sorted by

View all comments

Show parent comment

11

u/WlmWilberforce 11d ago

Set tab = 4*spaces in your editor

3

u/Dr_Gregg 11d ago

You cant as easily change the indentation width of spaces in your text editor

2

u/4Floaters 10d ago

What text editor are you using?

1

u/Dr_Gregg 9d ago

Emacs/vim

2

u/WlmWilberforce 9d ago

Back in my day this wouldn't work. It was Emacs or vi/vim. This editor miscegenation was not allowed.

2

u/Dr_Gregg 9d ago

Lmao, sorry! I like both. I started with vim a few years ago and became enamored with its modal keybinding and increasingly frustrated with its design otherwise. Doom emacs came to me as a way to get the keymaps I was used to with the power and (better) design of modern emacs

2

u/catbrane 9d ago

Most text editors can, in vim for example it's :set sw=4 ts=4. Set it as a rule for YAML in your vimrc and all yaml will use that setting.

1

u/Dr_Gregg 9d ago

Interesting, I will look into this thanks. Does it differentiate between spaces used for indentation and non-indentation spaces?

2

u/catbrane 9d ago

Oh I answered too quickly, sorry. That's for changing the size that tabs display as.

To change space indent size in vim, you need to change to tab indents, change the shift width and tab stop, then swap back to spaces.

:set noexpandtab  # into hard tab mode
:retab            # redo all indents with tabs
:set ts=4         # set new tab stop 
:set expandtab    # back to soft tab mode
:retab            # and swap tabs back to spaces

You can make that into a macro and bind it to a key.

(not a vim expert, I expect there's a better way)

1

u/Dr_Gregg 9d ago

Ah so my problem stands 😒. Tabs > spaces for accessibility. Conversion methods like this are nice but they are hacky at best

1

u/catbrane 8d ago

You want to use hard tabs (tab characters in the file, not multiple spaces)? Then it's easy, just:

:set ts=4 sw=4

ts is tab stop, so how many spaces tabs display as, and sw is shift width, so how far (in spaces) pressing tab indents by.

You can set those two any time and the display will change immediately, and the file won't change.

Add lines like this to your vimrc to make it change automatically by file type:

autocmd Filetype c setlocal ts=4 sw=4 noexpandtab
autocmd Filetype html setlocal ts=2 sw=2 softtabstop=2 expandtab

So hard tabs for C (everyone uses proper tabs there), but soft tabs (spaces) for html.

1

u/catbrane 8d ago

You can also set it per project. Make a .editorconfig file in the project root with eg.

# http://editorconfig.org

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{cpp,c,h}]
indent_style = tab
indent_size = 4

[*.py]
indent_style = space
indent_size = 4

vim and emacs will both the most-enclosing editorconfig and set behaviour from that.

1

u/Blue_Moon_Lake 11d ago

I don't want to use spaces, I want to use \t