On 04/14/2010 05:37 AM, Jorge Timón wrote:
After experiment a little, I finally solved it by:
g/^\d\+\./exec '.w!>> '.(['Buddingtonite.txt', 'Alunite.txt',
'calcite.txt', 'kaolinite.txt'][line('.')%6])
I'm surprised you didn't need 6 entries in that list...
g seems to be a very powerful command that I really need to learn.
It is...you can read up at
:help :g
but the general gist is "on every line matching /pattern/ perform
one-or-more Ex commands". There's an inverse using :v for
performing one or mor Ex commands on lines that *don't* match
/pattern/
^\d\+\. any line that begins with one (or more) decimal numbers
followed by a dot
yep
I don't understand everything this part
/exec '.w!>> '.(['D', '', '', 'A', 'B', 'C'][line('.')%6])
after exec, can you write any command?
exec allows you to build a command to be executed and then run it.
:help :exec
.w what is this dot for?
by default, ":w" writes the entire file ("1,$") to the file.
Adding the "." means "I only want to write this line"
>> like> in shell?
Yes, the ">>" appends to the specified file
:help :w_a
'. again, what is this dot for?
this concatenates the "write this line, appending to" portion
with the filename that is later composed...
(['D', '', '', 'A', 'B', 'C'][line('.')%6]) I think I
understand it, but where can I read about this kind of things?
([List of files][a way to send different parts to the
different files in the previous list])
This composes a list of hard-coded list of filenames using the
list-creation syntax
:help E696
and the indexes into them
:help list-index
based on the current line the :g command is looking at
("line('.')"). It uses modulo arithmetic to take that line#,
divides by 6, and looks at the remainder
:help expr-%
yielding a number from 0-5 (inclusive) with which to index the array.
line('.') why '.' ? is there a way to chose characters, words or
paragraphs instead of lines?
Yes, "." is the current line the :g command is looking at
:help :.
Vim has very powerful ways of working with lines using the :g/:v
commands, but is less flexible in working with
characters/words/paragraphs instead. It's doable, but often
involves more work.
where can I read about g command?
as mentioned above
:help :g
Sorry about my English too, just in case.
The English has been more than sufficient to convey your question
and response! :) Solo espero q' mi espanol fue tan util.
-tim
--
You received this message from the "vim_use" 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
To unsubscribe, reply using "remove me" as the subject.