The following command will substitute all tabs in a file with four blank spaces:
%s/\t/ /g
In order to run this command whenever I open a new file I included it in my .vimrc by adding:
autocmd BufNewFile * exec "%s/\t/ /g"
However this didn't work. Does anyone know why?
BufRead
? – Rich May 24 '18 at 9:02:retab
command. – Rich May 24 '18 at 9:04readonly
ornomodifiable
it will probably throw a bunch of errors, also the use ofgdefault
has to be considered. I would not recommend this setting! Better would be to set yourtabstop
setting appropriately and have Vim display tabs as 4 spaces. – Christian Brabandt May 24 '18 at 9:50