unexpected result using autocmd

46 views
Skip to first unread message

Mike

unread,
Oct 1, 2026, 10:41:59 PM (4 days ago) Oct 1
to vim...@googlegroups.com
Hi all,

I'm seeing unexpected behavior when using an autocmd defined in a
plugin. A simplified version of the plugin is the following:

function! InsertText()
echomsg "modified option is " .. &modified
call append(line("$"), "section title")
echomsg "modified option is " .. &modified
endfunction

autocmd FileType fortran call InsertText()
command -nargs=0 ForNoFT call InsertText()

It's purpose is to automatically insert lines in files that have a
specified filetype or to provide that service for other files. In the
above example, I've used "fortran" but I think any vim-recognized
filetype will do.

To show the problem, edit a Fortran file, e.g. run "vim test.f90". You
will see the text "section title" in the buffer. However, even though
the 'modified' option is set, I am allowed to quit vim (:q). Also, ^G
does not show modified. This behavior occurs whether the file
"test.f90" is new or has content.

A user-command has been defined in the plugin, intended for files
without a filetype. When you run "vim test.unknown" and then run the
user-command "ForNoFT", quit will fail as expected and ^G will show
modified.

Interestingly, if 'modified' is explicitly set in the function, then vim
will not quit because it sees test.f90 as modified.

My question is why the difference?
I'm running vim 9.2.1036 with normal features on Windows 10.

Thanks for any help.
-mike



Maxim Kim

unread,
Oct 2, 2026, 2:31:21 AM (4 days ago) Oct 2
to vim_use
This looks like a bug, worth creating an issue in vim's github.

echo getbufinfo(bufnr()) says that `changed: 0` however `changedtick` is greater than 0

As for 

>  It's purpose is to automatically insert lines in files that have a
specified filetype or to provide that service for other files

check :h skeleton

But it would have the same issue as with Filetype

Maxim Kim

unread,
Oct 2, 2026, 2:54:16 AM (4 days ago) Oct 2
to vim_use

The help topic for 'modified' specifically mention some events that do not set it, although missing the Filetype event.

Mike

unread,
Oct 2, 2026, 9:28:44 AM (3 days ago) Oct 2
to vim...@googlegroups.com
Maxim,

On 10/02/2026 2:31 AM, Maxim Kim wrote:
> This looks like a bug, worth creating an issue in vim's github.
Okay, I will do so.>
> echo getbufinfo(bufnr()) says that `changed: 0` however `changedtick` is
> greater than 0
>
> As for
>
>> It's purpose is to automatically insert lines in files that have a
> specified filetype or to provide that service for other files
>
> check :h skeleton
Thanks for the tip. I've never seen this example in help even though it
pre-dates Vim 7.0. Learn something new every day.>

Mike

unread,
Oct 2, 2026, 9:30:26 AM (3 days ago) Oct 2
to vim...@googlegroups.com
On 10/02/2026 2:54 AM, Maxim Kim wrote:
> https://github.com/vim/vim/issues/21427
>
> The help topic for 'modified' specifically mention some events that do not
> set it, although missing the Filetype event.
Yes, I saw this as well. Perhaps it should be part of the bug-fix.>
Reply all
Reply to author
Forward
0 new messages