Prev: ANN: Seed7 Release 2010-01-03
Next: problem with encrypted stream over simple client server link
From: Noob on 5 Jan 2010 08:19 Hello, I'm trying to clean up a C source file with gvim. (Might not be the appropriate tool...) AFAICT, I can delete trailing white space with :%s,[ \t]\+$,,g i.e. delete space and tab occurring at least once before newline However, I don't see how to replace N /leading/ tabs with 2N spaces. (I don't want to just replace every tab with two spaces because there are non-leading tabs which I want to handle differently.) Matching them would be /^[\t]\+ but how do I tell the editor to replace N tabs with 2N spaces? Regards.
From: Rainer Weikusat on 5 Jan 2010 08:37 Noob <root(a)127.0.0.1> writes: > I'm trying to clean up a C source file with gvim. > (Might not be the appropriate tool...) [...] > However, I don't see how to replace N /leading/ tabs with 2N spaces. You don't always have to be clever. #include <stdio.h> int main(void) { int tabbing, c; tabbing = 1; while ((c = getchar()) != EOF) { if (tabbing) { switch (c) { case '\t': putchar(' '); c = ' '; break; case '\n': break; default: tabbing = 0; } } else if (c == '\n') tabbing = 1; putchar(c); } return 0; }
From: Nicolas George on 5 Jan 2010 08:49 Noob wrote in message <hhve8p$2ov$1(a)speranza.aioe.org>: > However, I don't see how to replace N /leading/ tabs with 2N spaces. You can do something like that: s/^\t*\zs\t/ / That will replace the last tab of a leading series of tabs with two spaces. You repeat the command until the editor does not find the pattern. You can also use perl: perl -i -pe 's/^(\t+)/" "x(length $1)/e'
From: Scott Lurndal on 5 Jan 2010 12:53 Noob <root(a)127.0.0.1> writes: >Hello, > >I'm trying to clean up a C source file with gvim. >(Might not be the appropriate tool...) > >AFAICT, I can delete trailing white space with > >:%s,[ \t]\+$,,g > >i.e. delete space and tab occurring at least once before newline > >However, I don't see how to replace N /leading/ tabs with 2N spaces. > >(I don't want to just replace every tab with two spaces because >there are non-leading tabs which I want to handle differently.) > >Matching them would be > >/^[\t]\+ > >but how do I tell the editor to replace N tabs with 2N spaces? > :%!pr -e2 -t -T scott
From: Scott Lurndal on 5 Jan 2010 12:56 scott(a)slp53.sl.home (Scott Lurndal) writes: >Noob <root(a)127.0.0.1> writes: >>Hello, >> >>I'm trying to clean up a C source file with gvim. >>(Might not be the appropriate tool...) >> >>AFAICT, I can delete trailing white space with >> >>:%s,[ \t]\+$,,g >> >>i.e. delete space and tab occurring at least once before newline >> >>However, I don't see how to replace N /leading/ tabs with 2N spaces. >> >>(I don't want to just replace every tab with two spaces because >>there are non-leading tabs which I want to handle differently.) >> >>Matching them would be >> >>/^[\t]\+ >> >>but how do I tell the editor to replace N tabs with 2N spaces? >> > >:%!pr -e2 -t -T > >scott Never mind, missed the "leading" part. scott
|
Next
|
Last
Pages: 1 2 Prev: ANN: Seed7 Release 2010-01-03 Next: problem with encrypted stream over simple client server link |