[vim/vim] recognize trailing comment markers in modeline instead of throwing error message (#1648)

375 views
Skip to first unread message

Konfekt

unread,
Apr 22, 2017, 8:09:32 AM4/22/17
to vim/vim, Subscribed

To set the filetype to xml for a file file.xml, append

<!-- vim:filetype=xml -->

to file.xml. With modeline set, :edit file.xml gives the error message

E518: Unknown option: -->

Vim should infer by the commentstring option that

commentstring=<!--%s-->

and therefore that --> is the closing comment marker, and not a modeline setting.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Michal Grochmal

unread,
Apr 22, 2017, 12:48:57 PM4/22/17
to vim/vim, Subscribed

Well:

Vim should infer by the commentstring option that

:h commentstring

Currently only used to add markers for folding, see |fold-marker|.

Therefore no, it doesn't.

And :h modeline

There are two forms of modelines.  The first form:
	[text]{white}{vi:|vim:|ex:}[white]{options}

(...)

Examples:
   vi:noai:sw=3 ts=6 ~
   vim: tw=77 ~

The second form (this is compatible with some versions of Vi):

	[text]{white}{vi:|vim:|Vim:|ex:}[white]se[t] {options}:[text]

(...)

Examples:
   /* vim: set ai tw=75: */ ~
   /* Vim: set ai tw=75: */ 

And you have two options, either

<!-- vim: ft=xml
-->

And

<!-- vi: set ft=xml: -->

Which is more compatible anyway.

Also, this probably should be in vim_users mailing list or vi.stackexhange.com. Not an issue on github (and be closed here).

Bram Moolenaar

unread,
Apr 22, 2017, 12:58:08 PM4/22/17
to vim/vim, Subscribed

The 'commentstring' option can only be set after detecting the filetype, thus it can't be used for the modeline.

Bram Moolenaar

unread,
Apr 22, 2017, 12:58:19 PM4/22/17
to vim/vim, Subscribed

Closed #1648.

Konfekt

unread,
Apr 22, 2017, 3:44:44 PM4/22/17
to vim/vim, Subscribed

For example, the markdown comment [//]: # ( vim: spell:spelllang=en: ) still produces the error message:

Error detected while processing modelines:
line  309:
E518: Unknown option: )

Konfekt

unread,
Apr 22, 2017, 3:51:40 PM4/22/17
to vim/vim, Subscribed

I am sorry, the set makes the difference. I thought it was about the trailing :. It's fine.

Reply all
Reply to author
Forward
0 new messages