3

I've been using Vim for 2 years now but most (basically all) of the advanced functionality I enjoy today is from the great community of plugins available from Vim.

As such I have plugins that drive code folding for php, javascript, html and css. I've been playing around with pipe-mysql for my local database development. So far its working great, but given the size of the files I am working in, I thought how nice it would be if I could define code folds in my SQL code.

Currently when I try to manually fold I get this helpful error:

E350: Cannot create fold with current 'foldmethod'

Running :set foldmethod? tells me foldmethod=syntax.

What I'd really like is some direction on the simplest path to enabling manual (if it will keep my folds after the file is closed) or marker as the foldmethod on just my .sql files.

Also, if I need to use foldmethod=marker, how do I define a custom marker syntax? I'd like to do something like #-- as that is valid sql comment syntax and shouldn't interfere with running the sql code.

If it helps, here is what I believe to be the relevant existing section from my .vimrc:

" Automatic Code Folding
set foldmethod=syntax
set foldlevelstart=1

let javaScript_fold=1         " JavaScript
let perl_fold=1               " Perl
let php_folding=1             " PHP
let sh_fold_enabled=1         " sh
let vimsyn_folding='af'       " Vim script
let xml_syntax_folding=1      " XML
  • if you use sqloracle syntax, syntax folding should work. – Christian Brabandt Oct 17 '16 at 8:43
3

You can use foldmethod=marker and use comments valid for SQL files with {{{ and }}}:

#-- {{{1
#-- 1}}}

Numbers are optional. Here's how it could look like enter image description here enter image description here

And to get foldmethod=marker in sql files you can use au BufRead,BufNewFile *.sql setlocal foldmethod=marker

  • setlocal foldmarker=<custom marker> was the other half of the equation for me. – Noah Goodrich Oct 17 '16 at 18:13

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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