Quantcast

Folding on markdown headers

classic Classic list List threaded Threaded
41 messages Options
123
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Folding on markdown headers

Eric Weir

When I create a file with markdown headers and save it, folding on the headers does not work.

When I create a file with markdown headers, save it, close the window, and open the file in a new window, folding on the headers works.

Why in the one case and not in the other?

Thanks,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA

"The most important thing is the tee-shirt."

Samara Alnafdage



--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Chris Jones-44
On Sat, May 19, 2012 at 12:25:26PM EDT, Eric Weir wrote:

> When I create a file with markdown headers and save it, folding on the
> headers does not work.
>
> When I create a file with markdown headers, save it, close the window,
> and open the file in a new window, folding on the headers works.
>
> Why in the one case and not in the other?

Guessing, but in case #1, you may want to reload the file.. Something
like :e would do it.

CJ

--
Mooo Canada!!!!

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Eric Weir

On May 19, 2012, at 1:44 PM, Chris Jones wrote:

> On Sat, May 19, 2012 at 12:25:26PM EDT, Eric Weir wrote:
>
>> When I create a file with markdown headers and save it, folding on the
>> headers does not work.
>>
>> When I create a file with markdown headers, save it, close the window,
>> and open the file in a new window, folding on the headers works.
>>
>> Why in the one case and not in the other?
>
> Guessing, but in case #1, you may want to reload the file.. Something
> like :e would do it.

Thanks, Chris. That did it.

This is one of the prime ways this non-programmer vim novice learns vim. I tried to get help with this from vim help. It did not help. I am not stupid, but I did not understand a word. [Well, the words, but not what as a collection they mean.] I thought about checking the FAQs, which I usually find helpful. This was much less trouble.

------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA
[hidden email]

"A man should be in the world as though he were not in it
so that it will be no worse because of his life."

- Wendell Berry

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Chris Jones-44
On Sat, May 19, 2012 at 04:18:51PM EDT, Eric Weir wrote:
>
> On May 19, 2012, at 1:44 PM, Chris Jones wrote:

> > On Sat, May 19, 2012 at 12:25:26PM EDT, Eric Weir wrote:

> >> When I create a file with markdown headers and save it, folding on
> >> the headers does not work.
> >>
> >> When I create a file with markdown headers, save it, close the
> >> window, and open the file in a new window, folding on the headers
> >> works.
> >>
> >> Why in the one case and not in the other?

> > Guessing, but in case #1, you may want to reload the file..
> > Something like :e would do it.

> Thanks, Chris. That did it.

> This is one of the prime ways this non-programmer vim novice learns
> vim. I tried to get help with this from vim help. It did not help.
> I am not stupid, but I did not understand a word. [Well, the words,
> but not what as a collection they mean.] I thought about checking the
> FAQs, which I usually find helpful. This was much less trouble.

Unlike word processors Vim does not do things behind your back unless
you ask him explicitly.

But it's not so much about being a programmer.. You don't have to be
a mechanic to drive a car.. This is more like the difference between
driving an automatic and a standard..

One of the things I like most about Vim.. you're in control..

CJ

--
WHAT YOU SAY??

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Eric Weir

On May 19, 2012, at 5:49 PM, Chris Jones wrote:

> Unlike word processors Vim does not do things behind your back unless
> you ask him explicitly.
>
> But it's not so much about being a programmer.. You don't have to be
> a mechanic to drive a car.. This is more like the difference between
> driving an automatic and a standard..

I'd like to say I didn't mean to complain, Chris, but in fact I guess I did. For that I apologize.

Actually, I like vim just the way it is. I wish I were better able to take advantage of its amazing capabilities. But I have learned a lot, most of it with the help of this list. I definitely would not be a vim user were it not for this list. A lot of smart, creative people. Generous and kind, too. For it I am very grateful.

Sincerely,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]

"Imagining the other is a powerful antidote to fanaticism and hatred."

- Amos Oz

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Chris Jones-44
In reply to this post by Eric Weir
On Sat, May 19, 2012 at 12:25:26PM EDT, Eric Weir wrote:

> When I create a file with markdown headers and save it, folding on the
> headers does not work.
>
> When I create a file with markdown headers, save it, close the window,
> and open the file in a new window, folding on the headers works.
>
> Why in the one case and not in the other?

On a different line, now that you have found a workaround...

What folding method are you using..?

Reason I'm asking is that I don't use ‘markdown’ (which I understand is
a lightweight markup language?) but I ran a quick test and both with
fdm=marker and fdm=suntax, I see folds being created instantly w/o
having to save or reload the buffer or any other action on my part.

Maybe s/o more knowledgeable than myself re: Vim's innards will chime in
& will be able to figure out what's going on and recommend some
autocommand trick or other that would force Vim to handle your folds
automatically and save you the trouble of reloading the file..?

CJ

--
SOMEBODY SET UP US THE BOMB

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Eric Weir

On May 20, 2012, at 12:20 AM, Chris Jones wrote:

> On Sat, May 19, 2012 at 12:25:26PM EDT, Eric Weir wrote:
>
>> When I create a file with markdown headers and save it, folding on the
>> headers does not work.
>>
>> When I create a file with markdown headers, save it, close the window,
>> and open the file in a new window, folding on the headers works.
>>
>> Why in the one case and not in the other?
>
> On a different line, now that you have found a workaround...
>
> What folding method are you using..?

At first I didn't know how to answer. I didn't find anything related to fold method in my .vimrc. Fortunately, I keep copies of emails pertaining to problems I've encountered and solved with the help of people here and at vim_mac. Thank God!

Turns out I'm using Vlad Irnov's markdown folding script. https://gist.github.com/1035030 I'd completely forgotten about it, but it is what takes care of it for me.

> Reason I'm asking is that I don't use ‘markdown’ (which I understand is
> a lightweight markup language?) but I ran a quick test and both with
> fdm=marker and fdm=suntax, I see folds being created instantly w/o
> having to save or reload the buffer or any other action on my part.

Maybe this is something Vlad overlooked? Whatever, the workaround is pretty simple, so thanks again for that.

Sincerely,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]

"Imagining the other is a powerful antidote to fanaticism and hatred."

- Amos Oz

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Chris Jones-44
On Tue, May 22, 2012 at 09:14:03AM EDT, Eric Weir wrote:

> On May 20, 2012, at 12:20 AM, Chris Jones wrote:

> > On Sat, May 19, 2012 at 12:25:26PM EDT, Eric Weir wrote:

> >> When I create a file with markdown headers and save it, folding on
> >> the headers does not work.
> >>
> >> When I create a file with markdown headers, save it, close the
> >> window, and open the file in a new window, folding on the headers
> >> works.
> >>
> >> Why in the one case and not in the other?
> >
> > On a different line, now that you have found a workaround...
> >
> > What folding method are you using..?

> At first I didn't know how to answer. I didn't find anything related
> to fold method in my .vimrc. Fortunately, I keep copies of emails
> pertaining to problems I've encountered and solved with the help of
> people here and at vim_mac. Thank God!
>
> Turns out I'm using Vlad Irnov's markdown folding script.
> https://gist.github.com/1035030 I'd completely forgotten about it, but
> it is what takes care of it for me.

I meant the value of the ‘foldmethod’ Vim option. What does ‘:set fdm?’
tell you?

| :h fdm
| :h folding

The script sets the fdm option to ‘expr’ for the current buffer/window,
which amounts to running user-written code for each line in the buffer.

In this particular case, the user-written code is a function named
‘Foldexpr_markdown()’. By the look of it, this function should create
a fold automatically wherever it sees a line that starts with an equal
sign in column one, followed by either an equal sign or white space.
A valid markdown header would be something such as  ‘= a header’.. or
‘=== another header’... etc.

So that if you if you add a line of the form: ‘= this is a header’ and
hit <Enter>, the script should run automatically and create a fold
immediately. At least that's the way I understand it.

> Maybe this is something Vlad overlooked? Whatever, the workaround is
> pretty simple, so thanks again for that.

I use a one-line expression to fold Vim help files that is quite similar
to the script you referred me to and it updates the folding immediately
when for instance I duplicate the first couple of lines of an existing
fold by copying and pasting it - I never have to reload the file.

At a glance I cannot see any particular reason why the above-mentioned
script shouldn't work the same.

What exactly do you mean by ‘when I create a file’..? How does it ‘not
work’?

CJ

--
Mooo Canada!!!!

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Eric Weir

On May 25, 2012, at 3:08 PM, Chris Jones wrote:

> On Tue, May 22, 2012 at 09:14:03AM EDT, Eric Weir wrote:
>
>>> On May 20, 2012, at 12:20 AM, Chris Jones wrote:
>>>
>>> What folding method are you using..?
>>
>> At first I didn't know how to answer. I didn't find anything related
>> to fold method in my .vimrc. Fortunately, I keep copies of emails
>> pertaining to problems I've encountered and solved with the help of
>> people here and at vim_mac. Thank God!
>>
>> Turns out I'm using Vlad Irnov's markdown folding script.
>> https://gist.github.com/1035030 I'd completely forgotten about it, but
>> it is what takes care of it for me.
>
> I meant the value of the ‘foldmethod’ Vim option. What does ‘:set fdm?’
> tell you?

Thanks, Chris. It depends on the filetype. If it's markdown the result is "foldmethod=expr." Otherwise "foldmethod=manual."

> The script sets the fdm option to ‘expr’ for the current buffer/window,
> which amounts to running user-written code for each line in the buffer.
>
> In this particular case, the user-written code is a function named
> ‘Foldexpr_markdown()’. By the look of it, this function should create
> a fold automatically wherever it sees a line that starts with an equal
> sign in column one, followed by either an equal sign or white space.
> A valid markdown header would be something such as  ‘= a header’.. or
> ‘=== another header’... etc.
>
> So that if you if you add a line of the form: ‘= this is a header’ and
> hit <Enter>, the script should run automatically and create a fold
> immediately. At least that's the way I understand it.

There are two types of markdown headers, Setext and atx. Setext uses equal sign or single underline underlining. atx uses hashmarks, #, ##, etc. I use the latter and the script folds on them fine.

>> Maybe this is something Vlad overlooked? Whatever, the workaround is
>> pretty simple, so thanks again for that.
>
> I use a one-line expression to fold Vim help files that is quite similar
> to the script you referred me to and it updates the folding immediately
> when for instance I duplicate the first couple of lines of an existing
> fold by copying and pasting it - I never have to reload the file.
>
> At a glance I cannot see any particular reason why the above-mentioned
> script shouldn't work the same.

Not a programmer. Since the script controls folding on markdown files I would look to it for an explanation. My guess about what's going on when a script or plugin seems not to be working as it should is often completely wrong.  

> What exactly do you mean by ‘when I create a file’..? How does it ‘not
> work’?

I start with an empty window, i.e., no file loaded. I type in a "#" and some text, do a <CR> and some more text, another <CR> and some more text, then write/save the file as a markdown file, i.e., with markdown extent. At that point the header is not highlighted and folding does not work. If I close the file and reopen it, highlighting and folding work.

Regards,
------------------------------------------------------------------------------------------
Eric Weir
1111 Clairemont Avenue J3 ~ Decatur, GA 30030
404-636-6142 ~ [hidden email]

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

scott-268
On Fri, May 25, 2012 at 06:35:28PM -0400, Eric Weir wrote:

> On May 25, 2012, at 3:08 PM, Chris Jones wrote:

> > On Tue, May 22, 2012 at 09:14:03AM EDT, Eric Weir wrote:
> >
> >>> On May 20, 2012, at 12:20 AM, Chris Jones wrote:

> > What exactly do you mean by ‘when I create a file’..? How does it ‘not
> > work’?

> I start with an empty window, i.e., no file loaded. I type in a "#" and some text, do a <CR> and some more text, another <CR> and some more text, then write/save the file as a markdown file, i.e., with markdown extent. At that point the header is not highlighted and folding does not work. If I close the file and reopen it, highlighting and folding work.

when you start with an empty window, you have done nothing to
tell vim what type of file you are going to create -- when you
add text it still doesn't know -- if you write the file with a
markdown extent, it COULD know if you would ask it to check
(writing doesn't trigger filetype detection) -- so to ask it you
might try something like

    :syntax enable

perhaps that will help?

sc

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Gary Johnson-4
On 2012-05-25, sc wrote:

> On Fri, May 25, 2012 at 06:35:28PM -0400, Eric Weir wrote:
>
> > On May 25, 2012, at 3:08 PM, Chris Jones wrote:
>
> > > On Tue, May 22, 2012 at 09:14:03AM EDT, Eric Weir wrote:
> > >
> > >>> On May 20, 2012, at 12:20 AM, Chris Jones wrote:
>
> > > What exactly do you mean by ‘when I create a file’..? How does it ‘not
> > > work’?
>
> > I start with an empty window, i.e., no file loaded. I type in a
> > "#" and some text, do a <CR> and some more text, another <CR>
> > and some more text, then write/save the file as a markdown file,
> > i.e., with markdown extent. At that point the header is not
> > highlighted and folding does not work. If I close the file and
> > reopen it, highlighting and folding work.
>
> when you start with an empty window, you have done nothing to
> tell vim what type of file you are going to create -- when you
> add text it still doesn't know -- if you write the file with a
> markdown extent, it COULD know if you would ask it to check
> (writing doesn't trigger filetype detection) -- so to ask it you
> might try something like
>
>     :syntax enable
>
> perhaps that will help?

That depends on how the markdown filetype is being detected, by
filename extension or by file content.

If the markdown filetype is being detected by file content,
executing

    :filetype detect

after you've written a number of lines of recognizable markdown
should work.

If the markdown filetype is being detected by filename extension,
you'll have to give your buffer a name, e.g.,

    :f myfile

before executing

    :filetype detect

The simplest may be to execute

    :set ft=markdown

or whatever the markdown filetype is actually called, as soon as you
open a new, empty window.

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Chris Jones-44
On Fri, May 25, 2012 at 07:17:57PM EDT, Gary Johnson wrote:
> On 2012-05-25, sc wrote:

[..]

> > when you start with an empty window, you have done nothing to tell
> > vim what type of file you are going to create -- when you add text
> > it still doesn't know -- if you write the file with a markdown
> > extent, it COULD know if you would ask it to check (writing doesn't
> > trigger filetype detection) -- so to ask it you might try something
> > like
> >
> >     :syntax enable
> >
> > perhaps that will help?

Not sure it's necessary.

> That depends on how the markdown filetype is being detected, by
> filename extension or by file content.

Eric's previous post says he writes it as a markdown file - i.e. with
a markdown extent. So I assume that the file type is detected via the
filename extension.

> If the markdown filetype is being detected by file content,
> executing
>
>     :filetype detect
>
> after you've written a number of lines of recognizable markdown
> should work.
>
> If the markdown filetype is being detected by filename extension,
> you'll have to give your buffer a name, e.g.,
>
>     :f myfile
>
> before executing
>
>     :filetype detect
>
> The simplest may be to execute
>
>     :set ft=markdown
>
> or whatever the markdown filetype is actually called, as soon as you
> open a new, empty window.

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?

CJ

--
ALL YOUR BASE ARE BELONG TO US!

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Chris Jones-44
In reply to this post by Eric Weir
On Fri, May 25, 2012 at 06:35:28PM EDT, Eric Weir wrote:
>
> On May 25, 2012, at 3:08 PM, Chris Jones wrote:

[..]

> Thanks, Chris. It depends on the filetype. If it's markdown the result
> is "foldmethod=expr." Otherwise "foldmethod=manual."

So it looks like the markdown script gets loaded when dealing with
a markdown file. I should have asked you to issue a ‘:verbose set fdm’.  

> > The script sets the fdm option to ‘expr’ for the current buffer/window,
> > which amounts to running user-written code for each line in the buffer.
> >
> > In this particular case, the user-written code is a function named
> > ‘Foldexpr_markdown()’. By the look of it, this function should create
> > a fold automatically wherever it sees a line that starts with an equal
> > sign in column one, followed by either an equal sign or white space.
> > A valid markdown header would be something such as  ‘= a header’.. or
> > ‘=== another header’... etc.
> >
> > So that if you if you add a line of the form: ‘= this is a header’ and
> > hit <Enter>, the script should run automatically and create a fold
> > immediately. At least that's the way I understand it.

> There are two types of markdown headers, Setext and atx. Setext uses
> equal sign or single underline underlining. atx uses hashmarks, #, ##,
> etc. I use the latter and the script folds on them fine.

OK. I wrongly assumed the hash marks introduced comments. Doesn't make
any difference, though. I have a feeling that the problem is that the
folding script is not executed when you create markdown files, only when
you read them.
 
> >> Maybe this is something Vlad overlooked? Whatever, the workaround
> >> is pretty simple, so thanks again for that.

Looks more like something is missing. I don't see markdown in the global
file type detection file (filetype.vim) but I'm running Vim 7.2. Now the
script only does folding. Did you download a syntax highlighting file
from somewhere else? Do you have any other ‘markdown.vim’ files on your
system? Seems there are 2-3 different syntax files lying around in
different repos (vim.org, github..).

[..]

> > What exactly do you mean by ‘when I create a file’..? How does it ‘not
> > work’?

> I start with an empty window, i.e., no file loaded. I type in a "#"
> and some text, do a <CR> and some more text, another <CR> and some
> more text, then write/save the file as a markdown file, i.e., with
> markdown extent. At that point the header is not highlighted and
> folding does not work. If I close the file and reopen it, highlighting
> and folding work.

I _believe_ this is usually done via autocommands. See my other post.

CJ

--
WE GET SIGNAL

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Eric Weir
In reply to this post by scott-268

On May 25, 2012, at 7:03 PM, sc wrote:

> when you start with an empty window, you have done nothing to
> tell vim what type of file you are going to create -- when you
> add text it still doesn't know -- if you write the file with a
> markdown extent, it COULD know if you would ask it to check
> (writing doesn't trigger filetype detection) -- so to ask it you
> might try something like
>
>    :syntax enable
>
> perhaps that will help?

Thanks, sc. Definitely does. I assumed the behavior was anomalous. Someone, I think Chris, suggested earlier that a simple ":e" would do the trick, and it seems to do so. [Is that a shortened version of the command you suggest?]

------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA  USA
[hidden email]

"The most important thing is the tee-shirt."

Samara Alnafdage



--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Eric Weir
In reply to this post by Chris Jones-44

On May 25, 2012, at 9:41 PM, 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?

Thanks, Chris. I have a version of that command in my .vimrc to get "mmd" recognized as a markdown filetype. [I actually use MultiMarkdown.] And that's the extent I've been using in the incidents I've been reporting on here. So the answer to your question would seem to be that it doesn't.  

Regards,
------------------------------------------------------------------------------------------
Eric Weir

"With an ounce of willingness, everything can change."

- Kim



--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Eric Weir
In reply to this post by Chris Jones-44

On May 25, 2012, at 10:12 PM, Chris Jones wrote:

>> On Fri, May 25, 2012 at 06:35:28PM EDT, Eric Weir wrote:
>>
>> Thanks, Chris. It depends on the filetype. If it's markdown the result
>> is "foldmethod=expr." Otherwise "foldmethod=manual."
>
> So it looks like the markdown script gets loaded when dealing with
> a markdown file. I should have asked you to issue a ‘:verbose set fdm’.  
>
> When in a markdown file, it gives "foldmethod=expr Last set from ~/.vim/after/ftplugin/markdown.vim"  
>
>> There are two types of markdown headers, Setext and atx. Setext uses
>> equal sign or single underline underlining. atx uses hashmarks, #, ##,
>> etc. I use the latter and the script folds on them fine.
>
> OK. I wrongly assumed the hash marks introduced comments. Doesn't make
> any difference, though. I have a feeling that the problem is that the
> folding script is not executed when you create markdown files, only when
> you read them.
>
>> Maybe this is something Vlad overlooked? Whatever, the workaround
>> is pretty simple, so thanks again for that.
>
> Looks more like something is missing. I don't see markdown in the global
> file type detection file (filetype.vim) but I'm running Vim 7.2. Now the
> script only does folding.

Thanks, Chris. I don't find that file in my .vim folder. I have Vim 7.3 [MacVim]. I don't know when it became effective, but my understanding is that markdown support is built into Vim. I thought I was getting folding and highlighting on regular markdown files, i.e., "md," but when I checked just now it appears that I am not. So I put the auto command you suggested in your previous response in my .vimrc. Then I get folding and highlighting, but only when opening a previously saved file.

> Did you download a syntax highlighting file
> from somewhere else? Do you have any other ‘markdown.vim’ files on your
> system? Seems there are 2-3 different syntax files lying around in
> different repos (vim.org, github..).

Again, I was under the impression that markdown support is now built in to Vim. Perhaps I am mistaken about that. I'll have to look into what syntax files are on my system. I don't believe I've added any to my Vim installation. Some [all?] of my plugins may have their own syntax files. I'm pretty sure one---VimWiki---does and it sets a fold method ['expr"], but only for VimWiki files. I'll check for others.    

Regards,
------------------------------------------------------------------------------------------
Eric Weir
Decatur, GA
[hidden email]

"A writer is a person for whom writing is more difficult
than it is for other people."

- Thomas Mann






--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

scott-268
In reply to this post by Eric Weir
On Sat, May 26, 2012 at 05:54:32AM -0400, Eric Weir wrote:

> On May 25, 2012, at 7:03 PM, sc wrote:

> > when you start with an empty window, you have done nothing to
> > tell vim what type of file you are going to create -- when you
> > add text it still doesn't know -- if you write the file with a
> > markdown extent, it COULD know if you would ask it to check
> > (writing doesn't trigger filetype detection) -- so to ask it you
> > might try something like
> >
> >    :syntax enable
> >
> > perhaps that will help?

> Thanks, sc. Definitely does. I assumed the behavior was anomalous.
> Someone, I think Chris, suggested earlier that a simple ":e" would
> do the trick, and it seems to do so.

as in perl, TMTOWTDI (there's more than one way to do it) -- many
others have been suggested in this thread

> [Is that a shortened version of the command you suggest?]

no, :e is shorthand for :edit, which reloads the buffer and triggers
filetype detection along the way

the bad news is you've just implied you don't know how to use vim's
extensive help system (or maybe you're intimidated by it?)

    :h :e

would have answered that for you -- i recommend spending some time
familiarizing yourself with the help system -- learn about helpgrep,
and try it out with

    :helpgrep filetype detection

there are about 24 hits on that specific string, and will take you to
many interesting places in Help as you :cn your way through them

sc

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Gary Johnson-4
In reply to this post by Chris Jones-44
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Chris Lott
In reply to this post by Eric Weir
On Sat, May 26, 2012 at 1:54 AM, Eric Weir <[hidden email]> wrote:
>
> Thanks, sc. Definitely does. I assumed the behavior was anomalous. Someone, I think Chris, suggested earlier that a simple ":e" would do the trick, and it seems to do so. [Is that a shortened version of the command you suggest?]
>

:e is essentially equivalent to "file open" in other editors -- so
when you use the command :e without a file name it opens (reloads) the
current file (see more on the command using :help :e)

What you are running into is that Vim has no way to automatically knew
the filetype of your file unless it can do so by recognizing the file
extension (or a modeline at the beginning or end of a file). So when
you start a new file and save it with the proper extension, the :e
reloads the file, recognizes the type, and Vim acts accordingly. In
other words, it does the same thing that you are doing when you set
the filetype automatically...

c
--
Chris Lott <[hidden email]>

--
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Folding on markdown headers

Chris Jones-44
In reply to this post by Eric Weir
On Sat, May 26, 2012 at 06:47:59AM EDT, Eric Weir wrote:
> On May 25, 2012, at 10:12 PM, Chris Jones wrote:

[..]

> I don't know when it became effective, but my understanding is that
> markdown support is built into Vim.

I ran a quick test on a freshly-installed Vim 7.3 and highlighting
worked out of the box with a 20-line markdown sample I grabbed online.

With Vim 7.3, $VIMRUNTIME/filetype.vim has the following lines:

| " Markdown
| au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,README.md  setf markdown

As soon as I issued a ‘:w /tmp/sample.mdown’ to write the [No Name]
buffer to disk , the markdown was highlighted.

In other words, the standard setup should take care of turning on
highlighting immediately after you write the file when you use one
of the above file extensions (*.markdown, *.mdown, *.mkd, etc.)

I would avoid ‘*.mmd’ & ‘*.md’ (not in the above list). Worse, per
filetype.vim, ‘*.md’ is something else: a modula2 file extension.

I proceeded to copy the folding script to ~/.vim/after/ftplugin/ under
‘markdown.vim’ and ran the same test. Sure enough, immediately after
I wrote the buffer to disk (:w /tmp/sample2.mdown) my 20 lines became
one single big fold.

> I thought I was getting folding and highlighting on regular markdown
> files, i.e., "md," but when I checked just now it appears that I am
> not. So I put the auto command you suggested in your previous response
> in my .vimrc. Then I get folding and highlighting, but only when
> opening a previously saved file.

Please remove... The ‘au...’ command above does the same thing. But the
fact that in your case, highlighting does not work on file creation is
interesting. As if Vim was never notified of the BufNewFile event..

> > Did you download a syntax highlighting file from somewhere else? Do
> > you have any other ‘markdown.vim’ files on your system? Seems there
> > are 2-3 different syntax files lying around in different repos
> > (vim.org, github..).

> Again, I was under the impression that markdown support is now built
> in to Vim. Perhaps I am mistaken about that. I'll have to look into
> what syntax files are on my system. I don't believe I've added any to
> my Vim installation. Some [all?] of my plugins may have their own
> syntax files. I'm pretty sure one---VimWiki---does and it sets a fold
> method ['expr"], but only for VimWiki files. I'll check for others.    

Immediately after you create the file you could check that the folding
script is loaded : run ‘:scriptnames’ and look for a line that says
~/.vim/after/ftplugin/markdown.vim (or the MacVim equivalent).

You need to do this on a dedicated Vim session.. start Vim on an empty
buffer, enter some markdown, save the file, and run :scriptnames.. If
the folding script isn't even loaded, folding is not going to work.

Then run ’:verbose set ft’ and ‘:verbose set syntax’ to see if they are
set to ‘markdown’ and then ‘:verbose set fdm’.. should say ‘expr’.

Pretty much stumped at this point.. Maybe s/o with access to MacVim
could run a quick test & let us know whether it works on their system?

CJ

--
Alex Perez is aliveeeeeeee!!!


--
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
123
Loading...