I use
:set noet|retab!
But the problem I ran into is replacing all instances of 4 spaces with tabs throughout the file. I need vim to replace only instances of 4 spaces at the beginning of lines.
If I remove! at the end of retab, spaces are not replaced anywhere.
I tried using a custom function that someone created:
" Retab spaced file, but only indentation command! RetabIndents call RetabIndents() " Retab spaced file, but only indentation func! RetabIndents() let saved_view = winsaveview() execute '% s@ ^\( \{'.&ts.'}\)\ +@ \=repeat("\t", len(submatch(0))/'.&ts.')@' call winrestview(saved_view) endfunc
but when I start, I get a small error message:
:RetabIndents
Error processing RetabIndents function:
line 2:
E486: pattern not found: ^ ({4}) +
Francis lewis
source share