if &diff only true in first file ?

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

if &diff only true in first file ?

M Kelly
Hi,

In my .vimrc I have

if &diff
  let b:mckgitstatus = "diff"
else
  autocmd BufReadPost,BufNewFile,FileReadPost * call MyGitStatus()
  autocmd BufUnload * call MyGitLeave()
endif

And in the first file window I do see "diff" status as expected.
But the second file window does not have the "diff" status, but my git stuff.

Any idea why if &diff does not work for the second file window ?

thx always for vim and your support,
-mark

--
--
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: if &diff only true in first file ?

M Kelly
I added a check in my lightline git branch routine to check for diff and set the correct "diff" status there, so its fixed now.
When I think about it, it makes sense this way. But at first I thought both files would go through the same .vimrc startup logic.
take care,
-mark

--
--
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: if &diff only true in first file ?

Tony Mechelynck
In reply to this post by M Kelly
On Wed, Mar 28, 2018 at 4:36 AM, M Kelly <[hidden email]> wrote:

> Hi,
>
> In my .vimrc I have
>
> if &diff
>   let b:mckgitstatus = "diff"
> else
>   autocmd BufReadPost,BufNewFile,FileReadPost * call MyGitStatus()
>   autocmd BufUnload * call MyGitLeave()
> endif
>
> And in the first file window I do see "diff" status as expected.
> But the second file window does not have the "diff" status, but my git stuff.
>
> Any idea why if &diff does not work for the second file window ?
>
> thx always for vim and your support,
> -mark

Simple: Your vimrc is run only once, at startup. At that point,
buffers have already been created (but not yet loaded) for all files
mentioned on the vim (or vimdiff or gvimdiff or...) command-line.
"b:mckgitstatus", a buffer-local variable, is only seen from the
buffer which was current while sourcing the vimrc, probably the first
one.

If you want your :if .. :else .. :endif construct to apply to all
buffers mentioned on the command-line, it should be wrapped in a
function called from an :argdo statement. OTOH, if you want your
autocommands to apply to all non-diff buffers whenever created, your
MyGitStatus and MyGitPost functions should test &l:diff directly
rather than b:mckgitstatus. CAUTION:

--
--
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: if &diff only true in first file ?

Tony Mechelynck
("Enter" got hit too fast)

On Wed, Mar 28, 2018 at 8:18 PM, Tony Mechelynck
<[hidden email]> wrote:

> On Wed, Mar 28, 2018 at 4:36 AM, M Kelly <[hidden email]> wrote:
>> Hi,
>>
>> In my .vimrc I have
>>
>> if &diff
>>   let b:mckgitstatus = "diff"
>> else
>>   autocmd BufReadPost,BufNewFile,FileReadPost * call MyGitStatus()
>>   autocmd BufUnload * call MyGitLeave()
>> endif
>>
>> And in the first file window I do see "diff" status as expected.
>> But the second file window does not have the "diff" status, but my git stuff.
>>
>> Any idea why if &diff does not work for the second file window ?
>>
>> thx always for vim and your support,
>> -mark
>
> Simple: Your vimrc is run only once, at startup. At that point,
> buffers have already been created (but not yet loaded) for all files
> mentioned on the vim (or vimdiff or gvimdiff or...) command-line.
> "b:mckgitstatus", a buffer-local variable, is only seen from the
> buffer which was current while sourcing the vimrc, probably the first
> one.
>
> If you want your :if .. :else .. :endif construct to apply to all
> buffers mentioned on the command-line, it should be wrapped in a
> function called from an :argdo statement. OTOH, if you want your
> autocommands to apply to all non-diff buffers whenever created, your
> MyGitStatus and MyGitPost functions should test &l:diff directly
> rather than b:mckgitstatus. CAUTION: 'diff' is a window-local setting and it is possible to have several windows, with 'diff' set differently, displaying the same buffer. If you only display each diff buffer in one window it ought to work.

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.