Re: Match something that not in the pattern
On Thu 19-Oct-06 9:26am -0600, Charles E Campbell Jr wrote: > So, to do what you ask with LogiPat's result: > > :g/^\%(\%(}}$\)[EMAIL PROTECTED])*$/j Please see my response to Tony Mechelynck. Your solution changes the text of Peng Yu's example to 5 lines. As I understand his goal, the correct answer has 2 lines. It is not a problem with your very clever LogiPat, it is the application within :global. Here's what I believe is happening during the original first 4 lines: First you join the first two lines. Then, since the original line 2 is no longer present, nothing is done with line 2. Next it joins lines 3 and 4. That's 2 lines so far. Actually, lines 1 through 4 should be joined to 1 line. -- Best regards, Bill
Re: Match something that not in the pattern
Peng Yu wrote: Hi, I have the following file segments. I want to concatenate all the lines with their next lines, except that it ends with "}}". I want to use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. Would you please help me to figure out how to match the lineend without "}}"? This problem is one that LogiPat can help with! (see http://vim.sourceforge.net/scripts/script.php?script_id=1290 or http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs, see "LogiPat") First, let's construct a pattern that matches all lines that don't end with }}: :echo LogiPat('!"}}$"') ^\%(\%(}}$\)[EMAIL PROTECTED])*$ Now, that has a bit more than is necessary, but it does work. I'm not sure what you want with that trailing '^' -- was that supposed to mean beginning-of-line? It isn't necessary if that's the case. So, to do what you ask with LogiPat's result: :g/^\%(\%(}}$\)[EMAIL PROTECTED])*$/j Regards, Chip Campbell
Re: Match something that not in the pattern
On Thu 19-Oct-06 2:28am -0600, you wrote: > Bill McCarthy wrote: >> On Wed 18-Oct-06 10:24pm -0600, A.J.Mechelynck wrote: >> >>> Peng Yu wrote: Hi, I have the following file segments. I want to concatenate all the lines with their next lines, except that it ends with "}}". I want to use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. Would you please help me to figure out how to match the lineend without "}}"? Thanks, Peng >>> To join every line not ending in }} with the following line, use the >>> ":j[oin]" >>> command on every line _not_ matching the pattern /}}$/ which means "two >>> closing braces at end of line". As a cherry on the cake, you can avoid >>> joining >>> the last line in the file (which has no following line): >>> >>> :1,$-1v/}}$/j >>> >>> See >>> :help multi-repeat >>> :help :join >> >> Let's assume those 10 lines in the example were the only >> lines in the buffer. >> >> vglobal will first mark lines 1-3 and 5-9. It will next >> apply the join command to each of those lines. The line >> numbers below refer to these original line numbers. >> >> The join on 1 will join lines 1&2, the no longer existing >> line 2 is skipped, join lines 3&4, join lines 5&6, skip 6, >> join 7&8, skip 8 and, finally, join 9&10. >> >> You end up with 5 lines. The goal is to end with 2 lines. >> > Hm, I see what you mean. Let's try a variation: > > :1,$-1v/}}$/while getline(".") !~ '}}$' | join | endwhile That could result in an infinite loop if there were no '}}$' in either of the last 2 lines - and an incorrect result if there was no '}}$' in the last line. It would work by replacing: getline(".") !~ '}}$' with: getline(".") !~ '}}$' && line(".") != line("$") -- Best regards, Bill
Re: Match something that not in the pattern
Bill McCarthy wrote: On Thu 19-Oct-06 2:28am -0600, you wrote: Bill McCarthy wrote: On Wed 18-Oct-06 10:24pm -0600, A.J.Mechelynck wrote: Peng Yu wrote: Hi, I have the following file segments. I want to concatenate all the lines with their next lines, except that it ends with "}}". I want to use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. Would you please help me to figure out how to match the lineend without "}}"? Thanks, Peng To join every line not ending in }} with the following line, use the ":j[oin]" command on every line _not_ matching the pattern /}}$/ which means "two closing braces at end of line". As a cherry on the cake, you can avoid joining the last line in the file (which has no following line): :1,$-1v/}}$/j See :help multi-repeat :help :join Let's assume those 10 lines in the example were the only lines in the buffer. vglobal will first mark lines 1-3 and 5-9. It will next apply the join command to each of those lines. The line numbers below refer to these original line numbers. The join on 1 will join lines 1&2, the no longer existing line 2 is skipped, join lines 3&4, join lines 5&6, skip 6, join 7&8, skip 8 and, finally, join 9&10. You end up with 5 lines. The goal is to end with 2 lines. Hm, I see what you mean. Let's try a variation: :1,$-1v/}}$/while getline(".") !~ '}}$' | join | endwhile That could result in an infinite loop if there were no '}}$' in either of the last 2 lines - and an incorrect result if there was no '}}$' in the last line. It would work by replacing: getline(".") !~ '}}$' with: getline(".") !~ '}}$' && line(".") != line("$") Hadn't thought of that. So IIUC our final try is 1,$-1v/}}$/ \ while getline(".") !~ '}}$' \ && line(".") != line ("$") \ | join \ | endwhile isn't it? Best regards, Tony.
Re: Match something that not in the pattern
On Thu 19-Oct-06 3:08am -0600, you wrote: > Hadn't thought of that. So IIUC our final try is > 1,$-1v/}}$/ > \ while getline(".") !~ '}}$' > \ && line(".") != line ("$") > \ | join > \ | endwhile > isn't it? For this vglobal approach, yes. I still prefer: %s/\v%(}})@
Re: Match something that not in the pattern
Bill McCarthy wrote: On Wed 18-Oct-06 10:24pm -0600, A.J.Mechelynck wrote: Peng Yu wrote: Hi, I have the following file segments. I want to concatenate all the lines with their next lines, except that it ends with "}}". I want to use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. Would you please help me to figure out how to match the lineend without "}}"? Thanks, Peng To join every line not ending in }} with the following line, use the ":j[oin]" command on every line _not_ matching the pattern /}}$/ which means "two closing braces at end of line". As a cherry on the cake, you can avoid joining the last line in the file (which has no following line): :1,$-1v/}}$/j See :help multi-repeat :help :join Let's assume those 10 lines in the example were the only lines in the buffer. vglobal will first mark lines 1-3 and 5-9. It will next apply the join command to each of those lines. The line numbers below refer to these original line numbers. The join on 1 will join lines 1&2, the no longer existing line 2 is skipped, join lines 3&4, join lines 5&6, skip 6, join 7&8, skip 8 and, finally, join 9&10. You end up with 5 lines. The goal is to end with 2 lines. Hm, I see what you mean. Let's try a variation: :1,$-1v/}}$/while getline(".") !~ '}}$' | join | endwhile Best regards, Tony.
Re: Match something that not in the pattern
On Wed 18-Oct-06 10:24pm -0600, A.J.Mechelynck wrote: > Peng Yu wrote: >> Hi, >> >> I have the following file segments. I want to concatenate all the >> lines with their next lines, except that it ends with "}}". I want to >> use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. >> >> Would you please help me to figure out how to match the lineend without >> "}}"? >> >> Thanks, >> Peng > > To join every line not ending in }} with the following line, use the ":j[oin]" > command on every line _not_ matching the pattern /}}$/ which means "two > closing braces at end of line". As a cherry on the cake, you can avoid joining > the last line in the file (which has no following line): > > :1,$-1v/}}$/j > > See > :help multi-repeat > :help :join Let's assume those 10 lines in the example were the only lines in the buffer. vglobal will first mark lines 1-3 and 5-9. It will next apply the join command to each of those lines. The line numbers below refer to these original line numbers. The join on 1 will join lines 1&2, the no longer existing line 2 is skipped, join lines 3&4, join lines 5&6, skip 6, join 7&8, skip 8 and, finally, join 9&10. You end up with 5 lines. The goal is to end with 2 lines. -- Best regards, Bill
Re: Match something that not in the pattern
On Wed 18-Oct-06 9:20pm -0600, Peng Yu wrote: > On 10/18/06, Bill McCarthy <[EMAIL PROTECTED]> wrote: >> You're fairly close. Assuming you visually marked those >> lines, this solution is magic: >> >> '<,'>s/\%(}}\)\@> >> but this solution is very magic: >> >> '<,'>s/\v%(}})@> >> :h /\@> :h /\v > Could you please explain what these commands mean? Sure, let's use the first one: '<,'>s/\%(}}\)\@s/pattern After you mark the text to be modified, hitting ":" gives you, on the command line, ":'<,'>". So all you type is ":s/pattern" - the "'<,'>" is typed by Vim. This command deletes the first occurrence of "pattern" on each line in the range. (2) Instead of "pattern" I used pat1\@j|s/}}/&\r/g This is equivalent to type two commands: (1) '<,'>j That joins all the lines in the range to just one line. (2) s/}}/&\r/g That substitute command operates on the single resulting line of the join command command. Every '}}' will be replaced by '}}\r'. Where the '&' is replaced by the whole matched pattern and '\r' is an EOL (although '\n' is an EOL in a pattern). -- Best regards, Bill
Re: Match something that not in the pattern
Peng Yu wrote: Hi, I have the following file segments. I want to concatenate all the lines with their next lines, except that it ends with "}}". I want to use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. Would you please help me to figure out how to match the lineend without "}}"? Thanks, Peng To join every line not ending in }} with the following line, use the ":j[oin]" command on every line _not_ matching the pattern /}}$/ which means "two closing braces at end of line". As a cherry on the cake, you can avoid joining the last line in the file (which has no following line): :1,$-1v/}}$/j See :help multi-repeat :help :join Best regards, Tony.
Re: Match something that not in the pattern
--- Peng Yu <[EMAIL PROTECTED]> wrote: > Hi, > > I have the following file segments. I want to concatenate all the > lines with their next lines, except that it ends with "}}". I want to > use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. [EMAIL PROTECTED] is the look-ahead assersion, you want the look-behind assertion which is \@http://www.totalgirl.com.au/slumberparty
Fwd: Match something that not in the pattern
-- Forwarded message -- From: Peng Yu <[EMAIL PROTECTED]> Date: Oct 18, 2006 9:19 PM Subject: Re: Match something that not in the pattern To: Bill McCarthy <[EMAIL PROTECTED]> On 10/18/06, Bill McCarthy <[EMAIL PROTECTED]> wrote: On Wed 18-Oct-06 8:03pm -0600, Peng Yu wrote: > I have the following file segments. I want to concatenate all the > lines with their next lines, except that it ends with "}}". I want to > use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. > > Would you please help me to figure out how to match the lineend without "}}"? You're fairly close. Assuming you visually marked those lines, this solution is magic: '<,'>s/\%(}}\)\@s/\v%(}})@ Could you please explain what these commands mean? Thanks, Peng
Re: Match something that not in the pattern
On Wed 18-Oct-06 8:03pm -0600, Peng Yu wrote: > I have the following file segments. I want to concatenate all the > lines with their next lines, except that it ends with "}}". I want to > use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. > > Would you please help me to figure out how to match the lineend without "}}"? You're fairly close. Assuming you visually marked those lines, this solution is magic: '<,'>s/\%(}}\)\@s/\v%(}})@
Re: Match something that not in the pattern
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Peng Yu wrote: > Hi, > > I have the following file segments. I want to concatenate all the > lines with their next lines, except that it ends with "}}". I want to > use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. > > Would you please help me to figure out how to match the lineend without > "}}"? > > Thanks, > Peng > > > 2.3766829304614354*^-12*d^3*Ith^2*z^6 - > 9.163340710959959*^-10*Ith^3*z^6 - 3.0207696015850803*^-10*d* >Ith^3*z^6 + 8.760261318791164*^-11*d^2*Ith^3*z^6 - > 3.492315374248676*^-12*d^3*Ith^3*z^6}} > fw100s200[d_,z_,Ith_] := 0.01515647826357657, 0.08956492396538135, > 246.40722214248873 - 0.48219974209354677*d + > 0.07494738483672195*d^2 - 0.0007155767500598704*d^3 - > 778.7338684688602*Ith + 5.330667362452238*d*Ith - > 0.6096508973274091*d^2*Ith + 0.00429237191519287*d^3*Ith + > 1465.675721942*Ith^2 - 15.92585633547399*d*Ith^2 + Well, I am still learning VIM but these 3 commands could do your job, if they are acceptable to you (they work for me!): :1,10s/\n/ \r/g :1,10s/}} /}}/g :1,10s/ \n//g :) - -- Anupam Srivastava Scientific Coworker Universität Stuttgart Get my public keys: gpg --keyserver subkeys.pgp.net --recv-keys DF8B2AFE 99F8BB81 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.0 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFFNtE27GZ7yN+LKv4RAgBQAJ9kEt5G99gxO1eZh9Rs+3XeZDVixQCfSj8p H2FzBiSjkjRSbby//mVRf94= =eR5i -END PGP SIGNATURE-
Match something that not in the pattern
Hi, I have the following file segments. I want to concatenate all the lines with their next lines, except that it ends with "}}". I want to use the pattern "\(}}\)[EMAIL PROTECTED]". It seems not working. Would you please help me to figure out how to match the lineend without "}}"? Thanks, Peng 2.3766829304614354*^-12*d^3*Ith^2*z^6 - 9.163340710959959*^-10*Ith^3*z^6 - 3.0207696015850803*^-10*d* Ith^3*z^6 + 8.760261318791164*^-11*d^2*Ith^3*z^6 - 3.492315374248676*^-12*d^3*Ith^3*z^6}} fw100s200[d_,z_,Ith_] := 0.01515647826357657, 0.08956492396538135, 246.40722214248873 - 0.48219974209354677*d + 0.07494738483672195*d^2 - 0.0007155767500598704*d^3 - 778.7338684688602*Ith + 5.330667362452238*d*Ith - 0.6096508973274091*d^2*Ith + 0.00429237191519287*d^3*Ith + 1465.675721942*Ith^2 - 15.92585633547399*d*Ith^2 +