Pergunta

So i need to edit something in every line except the ones that begin with #, because they are comments. I need to replace all tabs by +.

I know in Vi I can translate stuff like this:

1,$s/a/A/g , replaces all a's by A

but how do i add the range which specifies all lines that don't start with #?

Foi útil?

Solução

The g (global) ex command does what you want:

:g!/^#/s/^I/+/g

The general format is g [!] /RE/ CMD, where RE is a pattern describing all the lines to apply the command to and CMD is any ex command. The optional ! reverses the sense of the RE, applying the command to all lines that DON'T match.

To get a TAB character on the line (the ^I above), you need to hit ctrl+V followed by TAB

Outras dicas

Seems like this could be achieved with a macro trick

qr/^[^#]<Enter>:s/\t/+<Enter>q
3000@r

Record a macro that will move to the next line which doesn't start with a #. Replace all spaces on that line with a tab character. Then just repeat that macro several hundred times (or whatever number is large enough for your file)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top