Hi vimmers,
I have a very strange problem and couldn't figure out what's going on.
I use the following function for commenting out a line or a block of
lines:
function! Komment2(commentLeader, commentTrailer)
if match( getline("."), "^\ *$" ) < 0
let save_cpo = &cpoptions
let save_paste = &paste
set cpo&vim
set paste
let escCommentLeader = escape(a:commentLeader, '^[.*\~]$')
let escCommentTrailer = escape(a:commentTrailer, '^[.*\~]$')
if getline(".") =~ '^\s*' . escCommentLeader . '.*' .
escCommentTrailer . '$'
execute "normal ^" . strlen(a:commentLeader) . "x$" .
strlen(a:commentTrailer)
. "hl" . strlen(a:commentTrailer) . "x"
else
execute "normal I" . a:commentLeader . "\<ESC>" . "A" .
a:commentTrailer . "\<
ESC>"
endif
let &cpo = save_cpo
let &paste = save_paste
endif
echo
endfunction
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 but just in case I mention that I have the
following syntax method set:
syn region myFold start='{' end='}' transparent fold
set foldmethod=syntax
Anyone has an idea what's going on?