> 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 unrelatedIt 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 ...
Thanks for the explanation, that's indeed what seems to be happening, but I still couldn't find a good way to circumvent it. How do other people deal with syntax folding and commenting?
