On Wed, 10 May 2006, Ben K. wrote:
Hi,
Is there a way to split a line automatically like awk would?
Given "A quick brown fox jumped over ",
awk '{print $3}' ... ==> brown
or like in perl
split(':',$line)...
I'd like to do within vim something like
:s/{some notation}/\3
without having to define the pattern
:s/\(\S\+\) \(\S\+\) \(\S\+\) ... /\3 ==> brown
using white space, and if needed, by defining my own separator
The regex to search for the <n>th occurence of a <search> is
/^\%(.\{-}\zs<search>\)\{<n>}
Given a line like
:A:quick:brown:fox:jumped:over
you can search for the <n>th word with
/^\%(.\{-}:\zs[^:]*\)\{<n>}
For example, if you want "fox", then do
/^\%(.\{-}:\zs[^:]*\)\{4}
You can easily modify the regex to use whitespace as delimiters.
HTH.
--
Gerald