I am using Neovim v0.10.0 and have the following config for git difftool
:
[diff]
tool = nvimdiff
[difftool]
prompt = False
trustExitCode = true
[difftool "nvimdiff"]
cmd = nvim -d \"$LOCAL\" \"$REMOTE\"
And git mergetool
:
[merge]
tool = nvimdiff
[mergetool]
prompt = false
keepBackup = false
Also in init.lua
, I define this global variable:
vim.g.diffmode = vim.api.nvim_get_option_value('diff', { win = 0 })
print('Diff mode: ' .. tostring(vim.g.diffmode)) // for debugging
I saw that the print statement showed vim.g.diffmode
to be true only when I used git difftool
, but false when I used git mergetool
.
However, when I run this in the command mode:
:lua print(vim.api.nvim_get_option_value('diff', {win=0}))
It showed true in every windows opened by git difftool
or git mergetool
.
What am I missing?
Update
Seems like with the git version I use (2.43.2), by default, nvimdiff
mergetool does not pass -d
to Neovim as an argument, after customizing the command to launch Neovim, like so:
[mergetool "nvimdiff"]
cmd = nvim -d -c '4wincmd w | wincmd J' \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"
I got it to work.
init.lua
run at a very early stage of initialization when the windows are not all created. Maybe should you tell us what you try to achieve such that we can help you better.nvim-lspconfig
andftplugin/java.lua
only when nvim is not opened in diff mode. The reason why I define a global flag for diff mode is because after many trials and errors, I found that when I dogit difftool
on a java file, theftplugin/java.lua
runs twice and the thevim.api.nvim_get_option_value('diff', {win=0})
only returns true on the first run. Defining a global flag like I mentioned solved this but not thegit mergetool
case.