I'm currentling using
:set noet|retab!
But the problem I'm running into is it's replacing all instances of 4 spaces to tabs throughout the entire file. I need vim to only replace instances of 4 spaces at the beginning of lines only.
If I remove the ! at the end of retab, spaces are not replaced anywhere.
I've tried using a custom function that somebody 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 I get a nice little error message when I run:
:RetabIndents
Error detected while processing function RetabIndents:
line 2:
E486: Pattern not found: ^( {4})+