How can I replace intraline tabs with spaces while maintaining alignment?

I like to use spaces for indentation, not tabs; replacing tabs at the beginning of a line is easy at sedor vim:

s/^I/    /g

But if there are tabs in the line (pretend that spaces are the width of the char tab):

'foo'^I ^I  => 'bar',
'bazzle'^I  => 'qux',

Each tab does not match a given number of spaces to maintain alignment. Does anyone have a tricky idea on how to replace these tabs with spaces while maintaining proper alignment?

+3
source share
2 answers

In Vim:

:retab

or, if you have tabs after spaces:

:retab!
+7
source

Linux BSD . expand , unppand . :

expand filename

, 4 , :

expand -t 4 filename

. , :

$ cp filename backup
$ expand -t 4 filename > tempfile
$ mv tempfile filename

vi:

$ vi filename
:%!expand -t 4
+9

Source: https://habr.com/ru/post/1719434/


All Articles