Andy Wokula schrieb:
Daniel Nogradi schrieb:
[...]
This function is a modified version of something I found in one of
the tips or scripts of the vim website. For C I use of course

Komment2('/* ', ' */')

and this works perfectly well, I can select a block of lines, call
the above function and every line will be commented out. It even
works in a toggling way, so commented lines will be uncommented. So
far so good, now comes the strange behaviour.

If there is a line which only contains a { character and that line is
commented out so it looks like /* { */ and then I call the above
function to uncomment it, everything below this line will be deleted.

It's probably unrelated

It is very related ...

but just in case I mention that I have the following syntax method
set:

syn region myFold start='{' end='}' transparent fold
set foldmethod=syntax

I just reproduced what happens:

With the (syntax) fold opened, go to the first / of the
comment
  /* { */
Then press "x" (or "3x" as the function does), this will remove the /
and CLOSE THE FOLD (WHY??)

The next "3x" will then remove the whole fold.

While trying this out, I had ft=vim set.  It obviously happens with
filetype C too.  It doesn't happen with some other filetypes.
Currently, I have no idea what's going on ...

IMHO there is nothing wrong, at least with Vim.
In fact, it's all about how syntax folding works.

In order to fold code, your additional syntax rule

syn region myFold start='{' end='}' transparent fold
set foldmethod=syntax

must get a chance to match text.  But as long as the '{' within
  /* { */
is hidden by the comment, your rule is not applied and therefore doesn't
fold anything.  Now if '/* ' is removed, resulting in
  { */
the Highlighter suddenly matches '{' with your rule and closes the fold
(depending on foldlevel etc.)

In a Vim script, the effect is the same, but for different reasons.
The line
  /* { */
is matched by the vimSearch group, hiding the '{' in it, but the text
  { */
again allows a match for '{' at top-level.

--
Regards,
Andy

EOM

Reply via email to