buttype == quickfix plus WinEnter

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

buttype == quickfix plus WinEnter

Wiere Neuer
I would like to set the (unfortunately global) scrolloff option dynamically.
To accomplish that, I use the following construct (simplified):

autocmd BufEnter * call SetScrollOff()

function SetScrollOff()
   let &scrolloff = &buftype == "quickfix" ? 3 : 5
endfunc

This approach works fine for non-quickfix windows.
However, when entering the quickfix window *for the first time* with e.g. :qf, scrolloff is not getting set.
When entering the quickfix window the next time, the approach works as intended.

Do I use the wrong
a) event,
b) comparison?

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: buttype == quickfix plus WinEnter

Tony Mechelynck
On Thu, Jan 4, 2018 at 12:00 PM, Axel Bender <[hidden email]> wrote:

> I would like to set the (unfortunately global) scrolloff option dynamically.
> To accomplish that, I use the following construct (simplified):
>
> autocmd BufEnter * call SetScrollOff()
>
> function SetScrollOff()
>    let &scrolloff = &buftype == "quickfix" ? 3 : 5
> endfunc
>
> This approach works fine for non-quickfix windows.
> However, when entering the quickfix window *for the first time* with e.g. :qf, scrolloff is not getting set.
> When entering the quickfix window the next time, the approach works as intended.
>
> Do I use the wrong
> a) event,
> b) comparison?
>

Try (untested)

                au BufEnter,BufNew * if &buftype == 'quickfix' | set
so=3 | else | set so=5 | endif

(all on one line of course)

Best regards,
Tony.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: buttype == quickfix plus WinEnter

Tony Mechelynck
Oh, and another possibility would be that your autocommand runs too
early, before the 'quickfix' buftype has been set. In that case you
may need to create the autocommand in an autocommand for the VimEnter
event, which is triggered at the very end of startup, when all global
plugins have had the time to create their own autocommands.

Best regards,
Tony.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: buttype == quickfix plus WinEnter

Wiere Neuer
In reply to this post by Wiere Neuer
@Tony

Thanks for your reply.

I already tried that first proposal of your's - to no avail...

Tested the second one - with the same result...

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: buttype == quickfix plus WinEnter

Ben Fritz
In reply to this post by Wiere Neuer
On Thursday, January 4, 2018 at 5:00:31 AM UTC-6, Axel Bender wrote:

> I would like to set the (unfortunately global) scrolloff option dynamically.
> To accomplish that, I use the following construct (simplified):
>
> autocmd BufEnter * call SetScrollOff()
>
> function SetScrollOff()
>    let &scrolloff = &buftype == "quickfix" ? 3 : 5
> endfunc
>
> This approach works fine for non-quickfix windows.
> However, when entering the quickfix window *for the first time* with e.g. :qf, scrolloff is not getting set.
> When entering the quickfix window the next time, the approach works as intended.
>
> Do I use the wrong
> a) event,
> b) comparison?
I have a similar set of autocmds. I used the &filetype rather than &buftype (maybe the autocmd predates the quickfix buftype?) but the intent is the same.

I also used BufEnter for my main autocmd.

However, I have a comment in my vimrc that "File type will not be set on the first BufEnter" followed by a second "FileType qf" autocmd to also set the scrolloff appropriately. Possibly the buftype acts the same way and you'll need to use the same method.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: buttype == quickfix plus WinEnter

Wiere Neuer
@Ben Fritz

Thanks for the answer. Using &filetype in place of &buftype - according to my findings - makes no difference. The *type is not available when entering the quickfix buffer for the first time. Shouldn't we consider this a bug and move the thread to vim_dev?

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: buttype == quickfix plus WinEnter

Ben Fritz
On Sunday, January 7, 2018 at 3:26:36 AM UTC-6, Axel Bender wrote:
> @Ben Fritz
>
> Thanks for the answer. Using &filetype in place of &buftype - according to my findings - makes no difference. The *type is not available when entering the quickfix buffer for the first time. Shouldn't we consider this a bug and move the thread to vim_dev?

I don't particularly care because of the easy workaround, but if it's not a bug then it's at least very unexpected, for 'buftype' especially.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.