sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.6k stars 101 forks source link

[Question] How to get a diffview between two files without VCS? #401

Closed jetm closed 12 months ago

jetm commented 12 months ago

Description

Thank you for diffview.nvim useful plugin.

Based on the documentation it looks it's not supported to get a diffview between two files are not under a Version Control Software. Is it that correct?

Expected behavior

I tried something like this nvim -d -c 'DiffviewOpen' /tmp/file1 /etc/file1.new and nvim -d -c 'DiffviewOpen /tmp/file1 /etc/file1.new'

Actual behavior

I was expecting to get a diff2_horizontal from two files that are not under a VCS. But it maybe not supported.

Steps to reproduce

nvim -d -c 'DiffviewOpen' /tmp/file1 /etc/file1.new or nvim -d -c 'DiffviewOpen /tmp/file1 /etc/file1.new'

Health check

Output of :checkhealth diffview ``` ============================================================================== diffview: require("diffview.health").check() Checking plugin dependencies ~ - OK nvim-web-devicons installed. Checking VCS tools ~ - The plugin requires at least one of the supported VCS tools to be valid. - OK Git found. - OK Git is up-to-date. (2.41.0) - WARNING Configured `hg_cmd` is not executable: 'hg' ```

Log info

Relevant info from :DiffviewLog ``` ############################ ### PUT LOG CONTENT HERE ### ############################ ```

Neovim version

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

Linux 6.1.38-1-MANJARO x86_64 GNU/Linux

Minimal config

-- #######################################
-- ### USAGE: nvim --clean -u mini.lua ###
-- #######################################

local root = vim.fn.stdpath("run") .. "/nvim/diffview.nvim"
vim.fn.mkdir(root, "p")

-- set stdpaths to use root
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "sindrets/diffview.nvim",
    dependencies = { "nvim-tree/nvim-web-devicons" },
    config = function()
      require("diffview").setup({
        -- ##############################################################################
        -- ### ADD DIFFVIEW.NVIM CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE ###
        -- ##############################################################################
      })
    end,
  },
  -- ##################################################################
  -- ### ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##################################################################
}
require("lazy").setup(plugins, { root = root .. "/plugins" })
require("lazy").sync({ show = false, wait = true })

vim.opt.termguicolors = true
vim.cmd("colorscheme " .. (vim.fn.has("nvim-0.8") == 1 and "habamax" or "slate"))

-- ############################################################################
-- ### ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ############################################################################
sindrets commented 12 months ago

What you're looking for is probably :h :diffsplit. It's a builtin command. Or if you want to start diff mode from the shell, see :h start-vimdiff.

jetm commented 12 months ago

thank you for the quick response. See above I am passing -d flag. That calls start-vimdiff.

sindrets commented 12 months ago

Yes, but you're using it wrong. As explained in the docs -d already starts nvim in diff-mode. You shouldn't be running :DiffviewOpen on top of that. You simply pass any 2-8 file arguments for the files you want to compare.

jetm commented 12 months ago

So, does it mean diffview cannot be used on top of diff mode?

sindrets commented 12 months ago

What do you mean? What do you expect to happen?

jetm commented 12 months ago

I was thinking diffview is an improvement over built-in diff-mode and the former will make better the experience diffing the changes.

sindrets commented 12 months ago

The plugin uses the builtin diff-mode as-is. What we build on top of that are diff related tools for working with VCS. Comparing revisions, editing staging areas, traversing and exploring file history, tracing line history, searching, filtering and ordering history etc.

jetm commented 12 months ago

I understand now. Thank you for the explanation.