Saturday, May 26, 2012

Re: Folding on markdown headers

On 2012-05-25, Chris Jones wrote:

> There are things I find a little unclear regarding autocommands but
> assuming the file extension is something like '*.mkdwn' shouldn't it be
> possible to achieve this automatically when creating the file by placing
> something like this in a file named ~/.vim/ftdetect/markdown.vim:
>
> | autocmd BufNewFile,BufRead *.mkdwn set filetype=markdown
>
> Wouldn't this cause ':w myfile.mkdwn' to automatically enable the
> markdown foldexpr and create the folds in one pass?

No. BufNewFile will set the filetype to markdown when starting to
edit a new file with a name ending in .mkdwn; BufRead will set it
when opening an existing file whose name ends with .mkdwn. To have
":w myfile.mkdwn" set the filetype, you would need to use the
BufWrite autocommand event. That's not normally done because one
usually wants any setting dependent on the file type executed when
starting to edit the file, not when the editing is finished.

The ways I usually set the filetype on new files is to open them by
name

$ vim foo.c

or

:split foo.c

or if I'm already in an empty buffer or the file doesn't have an
extension (e.g., a shell script), by executing

:set ft=c

Regards,
Gary

--
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

No comments:

Post a Comment