neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

difftool.lua (784B)


      1 if vim.g.loaded_difftool ~= nil then
      2  return
      3 end
      4 vim.g.loaded_difftool = true
      5 
      6 vim.api.nvim_create_user_command('DiffTool', function(opts)
      7  if #opts.fargs == 2 then
      8    require('difftool').open(opts.fargs[1], opts.fargs[2])
      9  else
     10    vim.notify('Usage: DiffTool <left> <right>', vim.log.levels.ERROR)
     11  end
     12 end, { nargs = '*', complete = 'file' })
     13 
     14 -- If we are in diff mode (e.g. `nvim -d file1 file2`), open the difftool automatically.
     15 local function start_diff()
     16  if not vim.o.diff then
     17    return
     18  end
     19  local args = vim.v.argf
     20  if #args == 2 then
     21    vim.schedule(function()
     22      require('difftool').open(args[1], args[2])
     23    end)
     24  end
     25 end
     26 if vim.v.vim_did_enter > 0 then
     27  start_diff()
     28  return
     29 end
     30 vim.api.nvim_create_autocmd('VimEnter', {
     31  callback = start_diff,
     32 })