0

Something I commonly do in files is add a modeline that says use this {{{...}}} pattern to delimit regions to be folded:

# vim: foldmethod=marker

When vim first opens the file, the text inside the {{{...}}} will be folded and I will get an overview of the sections of the file.
I can then use "file wide" commands to target all the folded sections, zm and zr, or just toggle a specific region with commands like zc or zo.

Something worth mentioning

I am running the ultisnips plugin, with snipmate type snippet files in ~/.vim/snippets.

The problem

When I have a snippet file in ~/.vim/snippets whose filetype is snippets. e.g. something like this: filename: ~/.vim/snippets/html.snippets

# vim: foldmethod=marker

# Global snippets

# HTML {{{
snippet font_oswald
    <link href='https://fonts.googleapis.com/css?family=Oswald:700,400' rel='stylesheet' type='text/css'>
snippet font_oswald_style
    .oswald {
        font-family: 'Oswald', sans-serif;
        font-style: normal;
        font-weight: 700;
        text-transform: uppercase;
        text-decoration: none;
        letter-spacing: 0em;
        word-spacing: 0em;
        line-height: 1.4;
    }
snippet font_roboto
    <link href='https://fonts.googleapis.com/css?family=Roboto:400,700,900' rel='stylesheet' type='text/css'>
snippet font_roboto_style
    .roboto {
        font-family: 'Roboto', sans-serif;
        font-style: normal;
        font-weight: 900;
        text-transform: none;
        text-decoration: none;
        letter-spacing: 0em;
        word-spacing: 0em;
        line-height: 1.4;
    }
# }}}

vim is not automatically folding the text when I open this file and the "file wide" command zm and zr dont work, but the fold specific commands zc or zo do still work.
The modeline setting is being recognised, i.e :set foldmethod? returns

foldmethod=marker

How can I get the "normal" behaviour to work in snippet files?

update

well I know its something to do with the ultisnips plugin as the problem goes away when I disable ultisnips.

0

Yes this is caused by this file in the ultisnips plugin:

~/.vim/bundle/UltiSnips/ftplugin/snippets.vim

particularly this block of code:

" Set some sane defaults for snippet files

if exists('b:did_ftplugin')
    finish
endif
let b:did_ftplugin = 1

let s:save_cpo = &cpo
set cpo&vim

" Fold by syntax, but open all folds by default
setlocal foldmethod=syntax
setlocal foldlevel=99

setlocal commentstring=#%s

setlocal noexpandtab
setlocal autoindent nosmartindent nocindent

I considered trying to disable this code by adding something like:

let b:did_ftplugin = 1

in my ~/.vimrc, but I suspect this did_ftplugin is scoped to a buffer?
So my solution so far has been to add this modeline to any snippet files

# vim: foldmethod=marker foldlevel=1

When I open the files the code is not folded, but I can fold it all with: zM

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.