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

Re: Changing windows in the filetype autocommand

Expand Messages
  • Hari Krishna Dara
    ... As a work-around (if no proper solution is found), you could also see if disabling some autocommands (such as BufNew and BufAdd) before doing a ... autocmd
    Message 1 of 3 , Apr 30, 2003
    • 0 Attachment
      On Wed, 30 Apr 2003 at 11:51am, Benji Fisher wrote:

      > Yegappan Lakshmanan wrote:
      > > Hi all,
      > >
      > > I am facing a problem in switching windows in a FileType
      > > autocommand.
      > >
      > > When a C file is loaded, I want to open a new window and position
      > > the cursor back in the original window.
      > >
      > > I tried using the following FileType autocmd:
      > >
      > > autocmd FileType c nested new | wincmd p
      > >
      > > With this autocmd, the filetype for the C file is detected
      > > as "conf" instead of as "C". Is this a bug?
      > >
      > > The above autocmd is an simplified form of the problem I
      > > am facing in using the taglist plugin.
      >
      > IIRC, there are problems with doing this that are not very well
      > documented. (Something like this came up on the list a few months ago and I
      > tried to find a solution then.) Basically, autocommands do not expect you to be
      > switching buffers while they are executing. Have you tried an alternative to
      > "wincmd p", like using winnr() ?
      >
      > HTH --Benji Fisher
      >

      As a work-around (if no proper solution is found), you could also see if
      disabling some autocommands (such as BufNew and BufAdd) before doing a
      :new could help. Something like this:

      autocmd FileType c nested :let _eventignore = &eventignore | set eventignore+=BufNew,BufAdd | new | wincmd p | let &eventignore = _eventignore

      You could try disabling other events too, such as WinEnter/WinLeave and
      BufWinEnter/BufWinLeave etc.

      HTH,
      Hari
    Your message has been successfully submitted and would be delivered to recipients shortly.