Wednesday, March 28, 2018

Re: if &diff only true in first file ?

On Wed, Mar 28, 2018 at 4:36 AM, M Kelly <mckelly2833@gmail.com> 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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: