Loading filetype scripts when editing a file on VimEnter

14 views
Skip to first unread message

John Jackson

unread,
Jun 1, 2026, 12:23:18 PM (yesterday) Jun 1
to Vim mailing list
Hello Vim users,

I want an installation of gVim to auto-edit a "notes" file when opened
with no arguments. I'm using this script in my Vim configuration:

vim9script
def LoadNotes()
  if argc() == 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
highlighting to the file. When I run :scriptnames, none of the Markdown
ftplugin or syntax scripts are listed. (Although many other ftplugin
script names are listed.)

If I manually run :edit after startup, then the syntax highlighting
works, and Vim's ftplugin\markdown.vim and its associated scripts are
now all listed in :scriptnames.

Is there a way to guarantee that Vim will load all of the needed
filetype scripts during the VimEnter event? Or is there a more
appropriate event for this use case? I'm happy to provide more details
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

黄岚军

unread,
9:31 AM (10 hours ago) 9:31 AM
to vim_use
Try adding `:filetype detect` to the line after `edit`.

John Jackson

unread,
10:18 AM (9 hours ago) 10:18 AM
to vim...@googlegroups.com
On 6/2/2026 9:22 AM, 黄岚军 wrote:
> Try adding `:filetype detect` to the line after `edit`.

This fixed it. Thank you!

John

Reply all
Reply to author
Forward
0 new messages