:update in autocmd doesn't trigger Write events

14 views
Skip to first unread message

Idan Kamara

unread,
Jan 14, 2012, 9:23:14 AM1/14/12
to vim...@googlegroups.com
Hi,

Calling update in an autocmd CursorMoved/I doesn't seem to trigger BufWritePost (or FileWritePost or FileAppendPost).

$ gvim -u NONE /tmp/foo.c

:au CursorMoved *.c silent up
:au CursorMovedI *.c silent up
:au BufWritePost *.c echo 'saved'

When I make changes to the file, it does call update but I never see 'saved' in the status bar.
Writing the file explicitly using :w does trigger it.

Basically what I'm trying to do is call update and do something if the buffer was actually saved.

Thanks.

Bram Moolenaar

unread,
Jan 15, 2012, 9:03:16 AM1/15/12
to Idan Kamara, vim...@googlegroups.com

Idan Kamara wrote:

:help autocmd-nested

--
A disclaimer for the disclaimer:
"and before I get a huge amount of complaints , I have no control over the
disclaimer at the end of this mail :-)" (Timothy Aldrich)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Idan Kamara

unread,
Jan 15, 2012, 9:55:38 AM1/15/12
to Bram Moolenaar, vim...@googlegroups.com
On Sun, Jan 15, 2012 at 4:03 PM, Bram Moolenaar <Br...@moolenaar.net> wrote:
>
>
> Idan Kamara wrote:
>
> > Calling update in an autocmd CursorMoved/I doesn't seem to trigger
> > BufWritePost (or FileWritePost or FileAppendPost).
> >
> > $ gvim -u NONE /tmp/foo.c
> >
> > :au CursorMoved *.c silent up
> > :au CursorMovedI *.c silent up
> > :au BufWritePost *.c echo 'saved'
> >
> > When I make changes to the file, it does call update but I never see
> > 'saved' in the status bar.
> > Writing the file explicitly using :w does trigger it.
> >
> > Basically what I'm trying to do is call update and do something if the
> > buffer was actually saved.
>
> :help autocmd-nested


Nice, thanks for the pointer.

I'm curious why ':au CursorMoved *.c nested update' triggers BufWritePost, but 'silent update' doesn't.
Couldn't find anything in the help regarding possible side-effects of :silent.
Reply all
Reply to author
Forward
0 new messages