Loading ...
Sorry, an error occurred while loading the content.

BufWinEnter autocmd is not invoked when splitting a window

Expand Messages
  • Yegappan Lakshmanan
    Hi all, The BufWinEnter autocmd is not invoked when splitting a window. According to the help for the BufWinEnter autocmd, this autocmd is invoked when a
    Message 1 of 2 , Sep 2, 2006
    • 0 Attachment
      Hi all,

      The BufWinEnter autocmd is not invoked when splitting a window.
      According to the help for the BufWinEnter autocmd, this autocmd
      is invoked when a buffer is displayed in a window.

      For example, use the following autocmd:

      au BufWinEnter * echomsg "Entering buffer " . expand("<afile>")

      With the above autocmd, if you execute the following commands:

      :e <somefile>
      :split

      The BufWinEnter autocmd is not invoked for the new window.

      But if you use the following commands, then the BufWinEnter autocmd
      is invoked:

      :e <somefile>
      :split <somefile>

      - Yegappan
    • Bram Moolenaar
      ... The BufWinEnter event is normally used to set window-local options for the file being edited. When you split a window you get all the option settings from
      Message 2 of 2 , Sep 3, 2006
      • 0 Attachment
        Yegappan Lakshmanan wrote:

        > The BufWinEnter autocmd is not invoked when splitting a window.
        > According to the help for the BufWinEnter autocmd, this autocmd
        > is invoked when a buffer is displayed in a window.
        >
        > For example, use the following autocmd:
        >
        > au BufWinEnter * echomsg "Entering buffer " . expand("<afile>")
        >
        > With the above autocmd, if you execute the following commands:
        >
        > :e <somefile>
        > :split
        >
        > The BufWinEnter autocmd is not invoked for the new window.

        The BufWinEnter event is normally used to set window-local options for
        the file being edited. When you split a window you get all the option
        settings from the existing window. Thus it's really a split, you don't
        get another buffer in a window.

        > But if you use the following commands, then the BufWinEnter autocmd
        > is invoked:
        >
        > :e <somefile>
        > :split <somefile>

        Vim doesn't check if the filename argument of :split happens to be the
        same as what is already being edited, thus it assumes it is another
        file and BufWinEnter is triggered. The file is reloaded too.

        --
        TALL KNIGHT: We shall say Ni! again to you if you do not appease us.
        ARTHUR: All right! What do you want?
        TALL KNIGHT: We want ... a shrubbery!
        "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ download, build and distribute -- http://www.A-A-P.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
      Your message has been successfully submitted and would be delivered to recipients shortly.