# Enable git update-diff automatically

**URL:** <https://discuss.kakoune.com/t/enable-git-update-diff-automatically/1252>\
**Category:** Help\
**Tags:** git\
**Created:** [September 3, 2020, 8:08pm UTC](https://discuss.kakoune.com/t/enable-git-update-diff-automatically/1252 "2020-09-03T20:08:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gustavo-hms](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/gustavo-hms/32/598_2.png) [@gustavo-hms](https://discuss.kakoune.com/u/gustavo-hms)\
**Post date:** [September 3, 2020, 8:08pm UTC](https://discuss.kakoune.com/t/enable-git-update-diff-automatically/1252/1 "2020-09-03T20:08:34Z")

</div>

Hi!

Could someone help me configuring Kakoune to automatically run `git show-diff` and `git update-diff` on file opening and updates? I tried with

```auto
hook global BufOpenFile .* %{ git show-diff }
hook global BufWritePost .* %{ git update-diff }

```

but without success. Probably I didn’t understand how to use hooks yet…

---

<div class="post-metadata">

**Author:** ![prion](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/prion/32/404_2.png) [@prion](https://discuss.kakoune.com/u/prion)\
**Post date:** [September 3, 2020, 10:13pm UTC](https://discuss.kakoune.com/t/enable-git-update-diff-automatically/1252/2 "2020-09-03T22:13:14Z")

</div>

Try

```auto
hook global WinCreate .* %{ git show-diff }

```

My suspicion is that BufOpenFile is triggered when the file is opened but before it is displayed. Additionally `git show-dif` sets the highlighter at the window level anyway so you would need to activate for each window regardless. In Kakoune a window is a view into a buffer.

---

<div class="post-metadata">

**Author:** ![vbauerster](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/v/85e7bf/32.png) [@vbauerster](https://discuss.kakoune.com/u/vbauerster)\
**Post date:** [September 4, 2020, 5:19am UTC](https://discuss.kakoune.com/t/enable-git-update-diff-automatically/1252/3 "2020-09-04T05:19:39Z")

</div>

I have following setup:

```auto
# enable flag-lines hl for git diff
hook global WinCreate .* %{
    add-highlighter window/git-diff flag-lines Default git_diff_flags
}
# trigger update diff if inside git dir
hook global BufOpenFile .* %{
    evaluate-commands -draft %sh{
        cd $(dirname "$kak_buffile")
        if [$(git rev-parse --git-dir 2>/dev/null)]; then
            for hook in WinCreate BufReload BufWritePost; do
                printf "hook buffer -group git-update-diff %s .* 'git update-diff'\n" "$hook"
            done
        fi
    }
}

```

---

<div class="post-metadata">

**Author:** ![gustavo-hms](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/gustavo-hms/32/598_2.png) [@gustavo-hms](https://discuss.kakoune.com/u/gustavo-hms)\
**Post date:** [September 8, 2020, 5:23pm UTC](https://discuss.kakoune.com/t/enable-git-update-diff-automatically/1252/4 "2020-09-08T17:23:53Z")

</div>

That worked! Thank you both!
