[vim/vim] `modelinescrict` causes `nomodeline` in modeline to be ignored (Issue #20103)

6 views
Skip to first unread message

Mao-Yining

unread,
Apr 30, 2026, 6:14:10 AM (11 days ago) Apr 30
to vim/vim, Subscribed
mao-yining created an issue (vim/vim#20103)

Steps to reproduce

When modelinescrict is enabled (which is the default), explicitly setting nomodeline in a file's modeline does not take effect. Vim continues to parse and apply other options from the modeline, contradicting the documented behavior.

Expected behaviour

I believe that setting nomodeline in a modeline should disable further processing of that modeline (i.e., ignore all other settings within it). This should be respected regardless of whether modelinescrict is enabled.

Version of Vim

9.2.0421

Environment

MS-Windows 11

Logs and stack traces


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/20103@github.com>

Mao-Yining

unread,
Apr 30, 2026, 6:15:28 AM (11 days ago) Apr 30
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#20103)

Related: #20028 which I also think is worth adding support.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/20103/4351591865@github.com>

Mao-Yining

unread,
May 10, 2026, 12:43:16 AM (yesterday) May 10
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#20103)

@chrisbra, please add modeline to modelinestrict.

This is mainly to disable it in certain files where it might be incorrectly matched. I think this is very reasonable and won't cause any security issues.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/20103/4414450193@github.com>

Christian Brabandt

unread,
May 10, 2026, 12:24:56 PM (24 hours ago) May 10
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#20103)

I don't understand the use case. Setting nomodeline in a modeline is too late when reading the current file. By that time the modeline is already being processed. That means setting nomodeline will only be affective when loading this particular file the next time. That sounds wrong.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/20103/4415764381@github.com>

Christian Brabandt

unread,
May 10, 2026, 12:30:45 PM (23 hours ago) May 10
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#20103)

I think this particular patch would allow to disable modelines in a modeline. But I am not sure of the use case yet and as such I am a bit hesitant to include it.

@@ -1590,7 +1589,12 @@ is_modeline_whitelisted(char *name)
  * if it can be changed.
  */
     static int
-validate_opt_idx(int opt_idx, int opt_flags, long_u flags, char **errmsg)
+validate_opt_idx(
+       int opt_idx,
+       int opt_flags,
+       long_u flags,
+       char **errmsg,
+       set_prefix_T prefix)
 {
     // Skip all options that are not window-local (used when showing
     // an already loaded buffer in a window).
@@ -1618,9 +1622,14 @@ validate_opt_idx(int opt_idx, int opt_flags, long_u flags, char **errmsg)
        }
        // When 'modelinestrict' is on, only whitelisted options may be
        // set from a modeline.  Silently skip others.
-       if (p_mlstr && opt_idx >= 0
-               && !is_modeline_whitelisted(options[opt_idx].fullname))
-           return FAIL;
+       if (p_mlstr && opt_idx >= 0)
+       {
+           // Allow disabling modelines
+           if (options[opt_idx].var == (char_u *)&p_ml && prefix == PREFIX_NO)
+               return OK;
+           else if (!is_modeline_whitelisted(options[opt_idx].fullname))
+               return FAIL;
+       }
 #ifdef FEAT_DIFF
        // In diff mode some options are overruled.  This avoids that
        // 'foldmethod' becomes "marker" instead of "diff" and that
@@ -2865,7 +2874,7 @@ do_set_option(
     }

     // Make sure the option value can be changed.
-    if (validate_opt_idx(opt_idx, opt_flags, flags, &errmsg) == FAIL)
+    if (validate_opt_idx(opt_idx, opt_flags, flags, &errmsg, prefix) == FAIL)
        goto skip;

     int cp_val = p_cp;


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/20103/4415776026@github.com>

Mao-Yining

unread,
9:58 AM (2 hours ago) 9:58 AM
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#20103)
*
But I am not sure of the use case yet

The modeline logic seems is to check the file header first, then the footer. This allows disabling modeline at the top to prevent false positives from the footer.

Example: neovim's :TOhtml plugin uses this ― it disables modeline at the beginning of the generated HTML file, avoiding unintended triggers near the end.

________________________________
发件人: Christian Brabandt ***@***.***>
发送时间: Monday, May 11, 2026 12:30:12 AM
收件人: vim/vim ***@***.***>
抄送: Mao-Yining ***@***.***>; Author ***@***.***>
主题: Re: [vim/vim] `modelinescrict` causes `nomodeline` in modeline to be ignored (Issue #20103)

[https://avatars.githubusercontent.com/u/244927 left a comment (vim/vim#20103)<https://github.com/vim/vim/issues/20103#issuecomment-4415776026>

Reply to this email directly, view it on GitHub<https://github.com/vim/vim/issues/20103#issuecomment-4415776026>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYJDXIVAHVIJWQCMWB2TSO342CVBDAVCNFSM6AAAAACYL7XNB2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DIMJVG43TMMBSGY>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905 or Android<https://play.google.com/store/apps/details
You are receiving this because you authored the thread.Message ID: ***@***.***>


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/20103/4421382362@github.com>

Mao-Yining

unread,
10:08 AM (2 hours ago) 10:08 AM
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#20103)

I think add it to whitelist is fine, cause when it is off it can’t be open by modeline again.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/20103/4421463880@github.com>

Reply all
Reply to author
Forward
0 new messages