Re: Loading filetype scripts when editing a file on VimEnter

黄岚军 <[email protected]> Tue, 2 Jun 2026 06:22:10 -0700 (PDT)
Newsgroups gmane.editors.vim
Message-ID <[email protected]>
------=_Part_88080_895567483.1780406530208
Content-Type: multipart/alternative; 
	boundary="----=_Part_88081_1915983871.1780406530208"

------=_Part_88081_1915983871.1780406530208
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Try adding `:filetype detect` to the line after `edit`.
=E5=9C=A82026=E5=B9=B46=E6=9C=882=E6=97=A5=E6=98=9F=E6=9C=9F=E4=BA=8C UTC+8=
 00:23:18<John Jackson> =E5=86=99=E9=81=93=EF=BC=9A

> Hello Vim users,
>
> I want an installation of gVim to auto-edit a "notes" file when opened=20
> with no arguments. I'm using this script in my Vim configuration:
>
> vim9script
> def LoadNotes()
>   if argc() =3D=3D 0
>     edit path\to\notes.md
>     echomsg "Auto-opened notes.md."
>   endif
> enddef
> autocmd VimEnter * ++once LoadNotes()
>
> This edits the file as expected. However, Vim does not apply syntax=20
> highlighting to the file. When I run :scriptnames, none of the Markdown=
=20
> ftplugin or syntax scripts are listed. (Although many other ftplugin=20
> script names are listed.)
>
> If I manually run :edit after startup, then the syntax highlighting=20
> works, and Vim's ftplugin\markdown.vim and its associated scripts are=20
> now all listed in :scriptnames.
>
> Is there a way to guarantee that Vim will load all of the needed=20
> filetype scripts during the VimEnter event? Or is there a more=20
> appropriate event for this use case? I'm happy to provide more details=20
> if they're helpful.
>
> :version
> VIM - Vi IMproved 9.2 (2026 Feb 14, compiled Feb 14 2026 12:17:29)
> MS-Windows 64-bit GUI/console version with OLE support
>
> John
>
>

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

---=20
You received this message because you are subscribed to the Google Groups "=
vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_use/374=
5a3e2-f3c3-4505-ad29-a78c004a3f8fn%40googlegroups.com.

------=_Part_88081_1915983871.1780406530208
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Try adding `:filetype detect` to the line after `edit`.<div class=3D"gmail_=
quote"><div dir=3D"auto" class=3D"gmail_attr">=E5=9C=A82026=E5=B9=B46=E6=9C=
=882=E6=97=A5=E6=98=9F=E6=9C=9F=E4=BA=8C UTC+8 00:23:18&lt;John Jackson> =
=E5=86=99=E9=81=93=EF=BC=9A<br/></div><blockquote class=3D"gmail_quote" sty=
le=3D"margin: 0 0 0 0.8ex; border-left: 1px solid rgb(204, 204, 204); paddi=
ng-left: 1ex;">Hello Vim users,
<br>
<br>I want an installation of gVim to auto-edit a &quot;notes&quot; file wh=
en opened=20
<br>with no arguments. I&#39;m using this script in my Vim configuration:
<br>
<br>vim9script
<br>def LoadNotes()
<br> =C2=A0 if argc() =3D=3D 0
<br> =C2=A0 =C2=A0 edit path\to\notes.md
<br> =C2=A0 =C2=A0 echomsg &quot;Auto-opened notes.md.&quot;
<br> =C2=A0 endif
<br>enddef
<br>autocmd VimEnter * ++once LoadNotes()
<br>
<br>This edits the file as expected. However, Vim does not apply syntax=20
<br>highlighting to the file. When I run :scriptnames, none of the Markdown=
=20
<br>ftplugin or syntax scripts are listed. (Although many other ftplugin=20
<br>script names are listed.)
<br>
<br>If I manually run :edit after startup, then the syntax highlighting=20
<br>works, and Vim&#39;s ftplugin\markdown.vim and its associated scripts a=
re=20
<br>now all listed in :scriptnames.
<br>
<br>Is there a way to guarantee that Vim will load all of the needed=20
<br>filetype scripts during the VimEnter event? Or is there a more=20
<br>appropriate event for this use case? I&#39;m happy to provide more deta=
ils=20
<br>if they&#39;re helpful.
<br>
<br>:version
<br>VIM - Vi IMproved 9.2 (2026 Feb 14, compiled Feb 14 2026 12:17:29)
<br>MS-Windows 64-bit GUI/console version with OLE support
<br>
<br>John
<br>
<br></blockquote></div>

<p></p>

-- <br />
-- <br />
You received this message from the &quot;vim_use&quot; maillist.<br />
Do not top-post! Type your reply below the text you are replying to.<br />
For more information, visit <a href=3D"http://www.vim.org/maillist.php">htt=
p://www.vim.org/maillist.php</a><br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;vim_use&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">vim_use+uns=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
vim_use/3745a3e2-f3c3-4505-ad29-a78c004a3f8fn%40googlegroups.com?utm_medium=
=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid/vim_use/374=
5a3e2-f3c3-4505-ad29-a78c004a3f8fn%40googlegroups.com</a>.<br />

------=_Part_88081_1915983871.1780406530208--

------=_Part_88080_895567483.1780406530208--