Hi Christian,
> Don't think so. I work with csv files a lot. And once I wanted to convert
> a large csv file on the fly into an sql insert script, extracting about
> 15 non-consecutive fields. This proved to be impossible without processing
> the data twice (running 2 separate :s commands).
Because I hit the same problem many times, I found a different way how to work
in these cases - using macro:
ggqq<edit the first line manually to convert csv line to the SQL
command>0jq1000...@q
Read as: go to the char #1 of the file, start macro 'q', edit manually the
first line so you get the desired result (SQL command etc.), stop editing, go
to the first char of the next line, stop the macro and now run that macro as
many times as you need (use any number higher than a number of lines in your
csv file).
The only trick is that you need to edit the original line in a way working for
all lines in the file: for example use motions like "go to the 3rd ';'" instead
of "go 37 chars right" because fields in your csv file are probably of
different lenght on each line. Nice trick to make this editing easier is to put
each field to some register and use those register later in the SQL command
composing. This is very similar to your idea of ${<number>}. Just don't use the
register you used for the name of the macro ('q' in my example):
0"adt;x"bdt;x"rdt;x"cdt;<...up to the end of the line>
ccNEW TEXT USING <C-R>b <C-R>a etc.
It may look little bit complicated for the first view but it is easy to use and
more powerful than :s command and regular expressions. You can do EVERYTHING
during the line editation, including calling the external commands etc.
Hope this helps,
Milan
P.S.: The same trick with macro can be used to do the (logically) same editing
action in more than one file. End the macro recording with ":wn" instead of
"0j".
--
Milan Vancura, Prague, Czech Republic, Europe
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php