Re: Silence inside functions please
- View SourceThus wrote Erik Janssen (erik.janssen@...) on :
> Preben Guldberg wrote:Actually it is more subtle than that - see below.
> > :g@^D \(\d\+\.\d\+ \d\d/\d\d/\d\d\) .*@
> > s//\1/
> > | +,/^COMMENTS:$/d
> > | -j
> FYI, in vm5.7 this is not going to work for multiple occurences as the
> deletion and join mess up the marking that is done beforehand, see
> manual page:
> The global commands work by first scanning through the [range] linesBut none of the lines matched by :global are changed or deleted.
> marking each line where a match occurs. In a second scan the [cmd] is
> executed for each marked line with its line number prepended. If a
> line is
> changed or deleted its mark disappears.
What I had not thought of when writing it up was that the search
pattern is changed between the first and second :subsitute command.
The way it works is
Use :g to mark all '^D delta' lines, then for each of them carry
out the sequence of commands, which goes (call the marks a...):
a 1) On first marked line, use last pattern (/^D \d.../) for :s
a 2) Deletes the next line and until /^COMMENTS:$/
a 3) Join some lines
b 1) On first marked line, use last pattern (/^COMMENTS:$) for :s
Oops, This does not match on the line matched by :global.
Thus it is necessary to repeat the :global pattern for the :substitute
> But I got it going by doing it in steps. Without your suggestions I[--- snip ---] Thanks for the example.
> would not have made it. (The input as I specified it was not completely
> correct: MR was not wrapped, version numbers are more complex and
> comments may span multiple lines, empty line below the comment always,
If your file only contains data, you might be able to pull it off with
:global's like below (though there is no checks for comment lines that
just say 'MRs:' or 'COMMENTS:' :-)
> This is how I did it, maybe someone who was following the thread mightHmm, a couple of comments:
> " Get the version number and the date from each line starting with DThe '$' at the end of the pattern is not necessary - the '.*' pattern
> g@^D \(\d\+\(\.\d\+\)\+ \d\d/\d\d/\d\d\) .*$@ s//\1/
is so greedy that it will match until end of line anyway.
> "Remove the MR + garbage + COMMENTI assume that a 'MRs:' line always follows the 'D version' line.
> " Join all non-empty linesThat was up to three lines of comments. (And I can tell you don't care
> " Repeat it
about spaces at the end of lines (you may get one for empty lines)).
> " Remove remaining empty linesIf you want to go that route, the is no 'jj' command. Make it 'j|j'.
> I think the g/.\+/j twice might be replaced by g/.\+/jj
Actually, you probably want one of
1) Allow spaces at tne of line:
2) No spaces at end of line in two steps
3) No spaces at end of line in one step
:g/./,/^$/j | s/ $//
Anyway, with the first :s issue above sorted out, try
g@^D \(\d\+\(\.\d\+\)\+ \d\d/\d\d/\d\d\) @
s@^D \(\d\+\(\.\d\+\)\+ \d\d/\d\d/\d\d\) .*@\1@
| s/ $//
The :g and :s patterns need not be the same (no grouping, except for
minor versions, are necessary), but it may be easier to maintain if
they look the same (though I did strip out the .* part, it still lines
"Before you criticize someone, walk
Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
c928400@... (o o) he gets angry, he'll be a mile away
----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
- View Source
> Second question: I run an external command that is quite long:Err.., you seem to have solved this already, but I think somebody should
> :r!sccs prs -e #|gawk 'very long awk script'
> It seems it is not possible to put newlines in the part that says
> 'very long awk script'? Is there a way to do this because now I've
> on one line.
mention the obvious:
:r!sccs prs -e #|gawk -f <name>.awk
i.e. Put the AWK stuff in a separate AWK-script-file <name>.awk and run
that. Works for me.
On a *nix command line you can use a multi-line AWK command by putting '\'
at the end of each line, except the last line.
awk '<1st line> \
<2nd line> \
This is not neccessary in an AWK script. I don't know if/how you can do this
on the vim command line.
- View SourceCoen Engelbarts wrote:
> Err.., you seem to have solved this already, but I think somebody should
> mention the obvious:
> :r!sccs prs -e #|gawk -f <name>.awk
> i.e. Put the AWK stuff in a separate AWK-script-file <name>.awk and run
> that. Works for me.
yes, the obvious was mentioned. I did not explicitly exclude it in the
original posting because I just intended to have a small question
answered, not a problem solved ;-)
I "dislike" the solution with a seperate file because my directories are
cluttered already with all those small awk files. I tend to forget their
use. This triggered the obvious remark by somebody else to use proper
names. I do that pretty consequently, but I still have this memory
problem... it's not a size issue, it's the refresh lines I'm afraid....
In a shell script there are indeed the '' or here documents to prevent
having to add another file. I was curious whether vim allows something
Anyway, i got my problem solved after all because they talked me out of
awk and I do it all in some not so unreadable regexps now. This
unfortunately adds some more messages while the script runs which was
actually the real issue of my posting, hence the subject.
well, one needs vim 6 for that and that's beta so it will have to wait a
But I did part of the future migration by making all my scripts
autonomous in adding mappings and menu's, i moved them to a $VIM/plugins
directory an added this clever trick I saw on vim.sf.net yesterday
if version < 600
exec "source " . substitute(glob($VIM."/plugins/*.vim"), "\n",
"\nsource ", "g")
I can recommend this for everybody who is delaying the move.