2

I use foldmethod=marker in vim with default {{{ and }}} markers and zfcommand to fold/unfold visually selected blocks.

It works fine in most file types, for example:

/*{{{*/
console.log("this is a javascript file")
/*}}}*/

<!--{{{-->
<p>This is a HTML file</p>
<!--}}}-->

/*{{{*/
/* This is a css file */
/*}}}*/

#{{{
echo "this is a bash script"
#}}}

Etc...

But in SQL files, it uses common /* ... */ syntax which, at least for PostgreSQL is invalid.

//{{{
select 'This is a SQL file'
//}}}

I also use tcomment pluggin to comment in and out things with Ctrl+- Ctrl+- and it works well with SQL files too so I think it should be an issue with zf command itself or some configuration parameter which I doesn't know. But I don't know where to look for...

For example:

-- select 'This is a commented out query'

Any clue or suggestion will be welcomed.

5
  • When in SQL file, what's the value for foldmethod and foldmarker?
    – grodzik
    Dec 9, 2016 at 12:19
  • foldmethod=marker, foldmarker={{{, }}}. But markers are right. What is wrong is the preffix to coment out that marker in valid sql syntax. I mean: when I type zf, I get /*{{{*/ [...] /*}}}*/ instead of --{{{ [...] --}}}.
    – bitifet
    Dec 9, 2016 at 12:31
  • 1
    Ah, now I get it. If you :set commentstring=--%s - does it work?
    – grodzik
    Dec 9, 2016 at 12:44
  • YES! Thanks. I thought that it should be a problem with folding configuration because, as I said, with tcomment it works, but probably is tcomment plugin which is doing it "wrong" in the sense of it ignorres commentstring.
    – bitifet
    Dec 9, 2016 at 12:48
  • ...now I only need to add an autocmd to set it for sql files. Thanks again!
    – bitifet
    Dec 9, 2016 at 12:49

1 Answer 1

2

As worked out in comments, solution is to set proper commentstring. The default is for sql file to commentstring=/*%s*/. So in this case you need to:

:set commentstring=--%s

You can automate it via autocmmand or by modeline:

-- vim:set commentstring=--%s:

.

autocmd FileType sql set commentstring=--%s
2
  • Of course! I just did it (thanks to your comments) and worked fine! Thanks.
    – bitifet
    Dec 9, 2016 at 13:00
  • As a note, it still doesn't work for syntax blocks ( vim.org/scripts/script.php?script_id=4168 ), but I will not cry for that. I rarely use them and, in this case is easy to temporary change the whole filetype while editing them.
    – bitifet
    Dec 9, 2016 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.