Tuesday, October 23, 2012

Re: changing buffers on windows

On Tuesday, October 23, 2012 6:45:38 AM UTC-5, Brandon Coleman wrote:
> On Tuesday, October 23, 2012 12:07:09 AM UTC-5, Ben Fritz wrote:
> > On Monday, October 22, 2012 9:58:06 PM UTC-5, Brandon Coleman wrote:
> >
> > > What is the suggested way to switch a buffer in a window that is displayed, but not the current window, or windows in other tab pages?
> >
> > >
> >
> >
> >
> > If you're asking how to change what buffer is displayed in a non-current window, you simply save the current window number, jump to the other window, change the buffer, and switch back to the saved window.
>
> That is what I am asking, but that seems like an error prone way of changing windows. If i'm writing a script that changes a window in a different tab page every time the current window is changed:
> 1. I would assume I would see the screen refresh a couple of time a window needed to be updated.

Maybe. 'lazyredraw' may or may not fix this, I'm not sure.

> 2. An autocommand could trigger as I am switching through windows/tabpages that could delete the window I am looking for. In this case I would update the window that took the previous windows place.
> 3. An autocommand could trigger as I am switching through windows/tabpages that could change a window in a way that I am now in an infinite window changing loop.
>

So ignore autocmds while your script processes. Prefix it with :noautocmd or add stuff to 'eventignore'. Even built-in stuff like the preview window and the options window load the new window by opening a new window or jumping to the correct existing window, loading the content, and then switching back to the original window. If it's on the same tab page, you can use "wincmd p" to switch back. If it's on a different tab page, just switching back to the old tab page should leave you still on the same window, especially if you ignore the TabLeave/TabEnter autocmds.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: