I would like vim to only ever insert a space character when I touch the space bar. Instead vim decides that sometimes tabs should be 4 spaces. How do I force vim to always and forever use tabs regardless of what any other vim config in my system says to do? No matter what I place in .vimrc it still gives me spaces.
1 Answer
If I’ve understood you correctly, you want to do something like this in your vimrc:
augroup
au!
au FileType * setlocal noexpandtab
augroup
But I cannot guarantee this works (i.e., something might get triggered after this autocommand that sets expandtab
). I think you could establish a buffer-local BufEnter
autocommand inside the FileType
autocommand, but that will be needless complexity if you never run into a situation where this doesn’t work.
I also cannot really recommend this... for one, I prefer spaces :) but additionally, this is very difficult to override when you want spaces!
A far better approach is to put setlocal noexpandtab
in ~/.vim/after/ftplugin/{filetype}.vim
anytime you run into a filetype that is using spaces where you want tabs.
-
2There's also other settings that can cause Vim to insert spaces even under
noet
, for instance ifsofttabstop
is set and&sts < &ts
or ifshiftwidth
is set,&sw < &ts
and you use the>
or<
commands, or indent/dedent withCTRL-T
orCTRL-D
or some automatic indentation withautoindent
... In short, it's not that easy to force tab indents everywhere...– filbranden ♦Mar 22, 2020 at 14:31 -
1
-
noexpandtab is set in both ~/.vimrc and ~/.vim/after/ftplugin/python.vim. When I hit tab on a blank line, I get a tab. When I hit tab to indent existing text, I get spaces. Mar 22, 2020 at 17:41
expandtab
, which may be set by ftplugin files.