>
> I think it has solved my first problem, it's amazing~~
Glad it mostly worked for you :)
> but I can't understand the expression very well, could you
> give me some more explanation about how you organize the
> command and what every part stand for?
That's
:g/ On every line that matches
^Lesson \d\+ "Lesson" at the beginning of the line
followed by one or more digits
/ perform the following action(s)
[1]
/^Abstract/ From the current match's line, search
forward for the word "Abstract" at the
beginning of the line
[2]
; through [3]
/^-\@!/ the next line that doesn't start with
a dash
t copy it ("it" = the range from "Abstract"
through the next non-dash line)
$ to the end of the file
Notes:
[1] the form is ":g/pattern/action", where "action" in this case
is a form of "{range}command"...the range happens to be specified
relatively by searching instead of by absolute line counts
[2] If you didn't want the word "Abstract" to be copied to your
results at the bottom, you could use "/^Abstract/+1" to start the
range on the line *following* "Abstract"
[3] This was my side-note/complaint in my previous email...I'm
not really sure why this doesn't work with a "," instead of a ";"
because I'm fairly certain I've done stuff almost exactly like
this before using the comma and it's worked.
[from your other email]
> through the help of manual, i can get the following symbol's meaning now.
>
> ^ To the first non-blank character of the line.
> |exclusive| motion.
>
> \d digit: [0-9] */\d*
>
> \+ Matches 1 or more of the preceding atom, as many as possible.
>
> /; E386 A very special offset is ';' followed by another search
> command.
>
> \@! Matches with zero width if the preceding atom does NOT match at the
> current position. |/zero-width| {not in Vi}
> Like '(?!pattern)" in Perl.
>
> remained question: what does "//" mean?
The "//" is actually the adjacency of the end of the ":g" command
and the beginning of a search relative-reference:
:g/pattern/command
^ the first "/"
where "command" is (as mentioned above in [1])
{range}t$
The "{range}" just happens to be "/^Abstract/;/^-\@!/"
^ the second "/"
> another question: "Lesson is disappeared?"
I'm not sure I understand how to interpret this:
1) You meant "'Lesson' is completely gone from my file?!"
No...if the file was big enough, the stuff dumped at the bottom
will fill the screen, hiding the original content (containing
"Lesson") at the top. My Ex command(s) perform no deletion (only
copies), so the top half of the file should remain the same. The
easiest way to see this is to put a bar at the bottom of your
original file (something like
:$put=repeat('=', 50)
or
G50A=<esc>
to put in a "=========="-type bar). That way, you can see where
the original data ended and where the Abstract collection begins
2) You meant "I wanted to copy 'Lesson' down as well, but forgot
to mention that in my original post about copying Abstracts" :)
That's a bit more complex, but not too bad. My first thought
(untested) would be something like changing my
:g/^Lesson \d\+//^Abstract/;/^-\@!/t$
to
:g/^Lesson \d\+/ka|t$|'a/^Abstract/;/^-\@!/t$
which
ka drops mark "a" on the Lesson line so we can come back
| then
t$ copies the Lesson line to the bottom
(which moves the current location to the bottom)
| and then
'a go back to the original Lesson line
... and do the rest of the stuff to copy the Abstract
It does require tromping on one of your bookmarks, so if you have
something sacred marked as "a", you can choose another bookmark
letter to use in both places.
For help targets on all of this (some of which you mentioned
finding):
:help :g
:help :range " especially about a page down on ";"
:help :t
:help :k
:help :'
:help :bar
:help /^
:help /\@!
:help /\d
:help /\+
Hope this gives you a clearer picture of how that command breaks
down and can be reworked.
-tim (the early-morning prolix pedagogue)
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment