On Jun 18, 7:31 am, Eric Weir <eew...@bellsouth.net> wrote:
> On Jun 17, 2011, at 3:57 PM, Vlad Irnov wrote:
> > You can also try one the popular light-weight markup languages:
> > Markdown, txt2tags, reST. In theory, they all can have folding set up
> > on headlines. I posted foldexpr for Markdown here:
> >http://groups.google.com/group/vim_use/browse_thread/thread/9beeb7aba...
>
> I've committed to something called MultiMarkdown. It's an extension of 
> Markdown. For me, the appeal is support for LaTeX, footnotes, citing, and 
> bibliography. Also, it's incorporated in another "editor" that I use. 
> [Scrivener. More than an editor. A very flexible editor with project 
> management capabilities and support for footnoting.]
>
> I've checked out your foldexpr for Markdown. I haven't a clue how it works. 
> [I'm a nonprogrammer Vim novice.] But if I could get or create one for the 
> atx style syntax for headers it might be the solution forme.


Vim 7.3 has support for Markdown by default. You just need to set
buffer 'filetype' to "markdown". MultiMarkdown and other dialects are
very similar, there is no need to create a new filetype.

File $VIMRUNTIME/filetype.vim defines file extensions associated with
Vim filetype "markdown":
    *.markdown,*.mdown,*.mkd,*.mkdn,README.md
Make sure your .vimrc has filetype detection turned on. Usually it's
line
    filetype plugin indent on
Then when you open a file with name ending in .markdown, .mkd and so
on, Vim will set filetype to "markdown".
You can also reload filetype-specific settings at any moment with the
command
    :set ft=markdown
To see the current 'filetype'
    :set ft?

Vim files responsible for "markdown" settings and syntax highlighting
are
    $VIMRUNTIME/ftplugin/markdown.vim
    $VIMRUNTIME/syntax/markdown.vim

Make sure you have "syntax on" in your .vimrc to enable syntax
highlighting.

Folding for markdown is not set up by default, you have to add it
yourself:
1) Create file
    $HOME/.vim/after/ftplugin/markdown.vim  (non-Windows)
        or
    $HOME/vimfiles/after/ftplugin/markdown.vim  (Windows)
where $HOME is Vim's HOME directory. This is where your custom vimrc
is. You can find out what it is with
    :echo $HOME
You may need to create folders /.vim or /vimfiles, /after, /after/
ftplugin first.
2) Copy the following code into it. WARNING: long lines may get split
during posting.

"----------------Markdown folding set up------------------
" folding for Markdown headers, both styles (atx- and setex-)
" http://daringfireball.net/projects/markdown/syntax#header
setl foldmethod=expr
setl foldexpr=Foldexpr_markdown(v:lnum)
func! Foldexpr_markdown(lnum)
    let l1 = getline(a:lnum)
    " ignore empty lines
    if l1 =~ '^\s*$'
        return '='
    endif
    " next line is underline
    let l2 = getline(a:lnum+1)
    if  l2 =~ '^=\+\s*'
        return '>1'
    elseif l2 =~ '^-\+\s*'
        return '>2'
    " current line starts with hashes
    elseif l1 =~ '^#'
        return '>'.matchend(l1, '^#\+')
    " keep previous foldlevel
    else
        return '='
    endif
endfunc

" change the following local settings to your liking
" see ':help fold-options' for more
setl foldenable
setl foldlevel=0
setl foldcolumn=0

" this is one line
setl foldtext=getline(v:foldstart).'\ \ \ /'.v:foldlevel.'...'.
(v:foldend-v:foldstart)

"----------------END of Markdown folding set up------------------

You can also add other buffer- and window-local settings to override
defaults:
:setl wrap list

To test, try it on some real and complex Markdown file, for example
save this file
https://raw.github.com/fletcher/peg-multimarkdown/master/README.markdown
and open it in Vim. You should get syntax hi and folding.

To try VOoM plugin with Markdown execute the command
:Voom markdown

Regards,
Vlad

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to