 |
|
| Computers Forum Index » Computer - Editors » [vim] how to delete comments... |
|
Page 1 of 1 |
|
| Author |
Message |
| Erhy... |
Posted: Mon Jun 15, 2009 1:49 am |
|
|
|
Guest
|
Hello,
I want to delete comments in html files.
Is it possible with a
:normal command?
for inserting in a command script
Thank you
Erhy |
|
|
| Back to top |
|
|
|
| Kaz Kylheku... |
Posted: Mon Jun 15, 2009 4:33 am |
|
|
|
Guest
|
On 2009-06-15, Tim Roberts <timr at (no spam) probo.com> wrote:
Quote: Second, you don't want it to be greedy. For example, you might try this:
:%s/<!--\_.*-->//
But that deletes from the start of the first comment to the end of the last
comment.
Aha, but you can replace the * with \{-} which is similar to * but matches the
shortest possible match, rather than the longest.
Try:
:%s/<!--\_.\{-}-->//
From Vim's help files (:help regex):
\{n,m} Matches n to m of the preceding atom, as many as possible
\{n} Matches n of the preceding atom
\{n,} Matches at least n of the preceding atom, as many as possible
\{,m} Matches 0 to m of the preceding atom, as many as possible
\{} Matches 0 or more of the preceding atom, as many as possible (like *)
\{-n,m} matches n to m of the preceding atom, as few as possible
\{-n} matches n of the preceding atom
\{-n,} matches at least n of the preceding atom, as few as possible
\{-,m} matches 0 to m of the preceding atom, as few as possible
\{-} matches 0 or more of the preceding atom, as few as possible
{Vi does not have any of these} |
|
|
| Back to top |
|
|
|
| Tim Roberts... |
Posted: Mon Jun 15, 2009 5:16 am |
|
|
|
Guest
|
"Erhy" <erhard _ glueck _ austria at (no spam) no.spam.hotmail.com> wrote:
Quote:
I want to delete comments in html files.
Is it possible with a
:normal command?
for inserting in a command script
Not easily. There are a number of issues here.
First, HTML comments are often multi-line affairs. Thus, you'll need to
use something like \_. to match characters across lines.
Second, you don't want it to be greedy. For example, you might try this:
:%s/<!--\_.*-->//
But that deletes from the start of the first comment to the end of the last
comment.
Third, remember that script blocks and stylesheet blocks are often
implemented as HTML comments in order to protect them from unsophisticated
old browsers. For example:
<style> <!--
p { margin-left: 50px; }
--> </style>
Personally, this is a task I'd relegate to a script in something like
Python, Perl, or Awk rather than relying on vi.
--
Tim Roberts, timr at (no spam) probo.com
Providenza & Boekelheide, Inc. |
|
|
| Back to top |
|
|
|
| Karthick... |
Posted: Tue Jun 16, 2009 7:28 am |
|
|
|
Guest
|
On Jun 16, 12:13 pm, "Erhy" <erhard _ glueck _
aust... at (no spam) no.spam.hotmail.com> wrote:
Quote: I hoped,
that I'm able to refer to the syntax rules,
which mark comments.
Erhy
Is that a comment, a question, or something else..? :)
Your original post is a totally different question.. Is it possible to
delete comments in html code using a :normal command.. Kaz's reply is
addressing that, isn't it? |
|
|
| Back to top |
|
|
|
| Erhy... |
Posted: Tue Jun 16, 2009 11:13 am |
|
|
|
Guest
|
I hoped,
that I'm able to refer to the syntax rules,
which mark comments.
Erhy |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Sun Mar 21, 2010 5:26 am
|
|