Integrate Meld file comparing into Neovim
This commit is contained in:
@@ -23,3 +23,29 @@ map({ "n", "v" }, "<leader>y", [["+y]], { noremap = true, silent = true, desc =
|
||||
|
||||
-- Paste from system clipboard
|
||||
map("n", "<leader>p", [["+p]], { noremap = true, silent = true, desc = "Paste from system clipboard" })
|
||||
|
||||
vim.keymap.set("n", "<leader>cc", function()
|
||||
local file1 = vim.fn.expand("%")
|
||||
|
||||
local project_root = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
|
||||
if project_root == "" then
|
||||
project_root = vim.fn.getcwd()
|
||||
end
|
||||
|
||||
require("telescope.builtin").find_files({
|
||||
prompt_title = "Compare with...",
|
||||
cwd = project_root,
|
||||
hidden = true,
|
||||
follow = true,
|
||||
attach_mappings = function(_, map)
|
||||
map("i", "<CR>", function(prompt_bufnr)
|
||||
local actions = require("telescope.actions")
|
||||
local action_state = require("telescope.actions.state")
|
||||
local file2 = action_state.get_selected_entry().path
|
||||
actions.close(prompt_bufnr)
|
||||
require("user.utils").meld_diff(file1, file2)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
})
|
||||
end, { desc = "Compare with" })
|
||||
|
||||
15
lazyvim/.config/nvim/lua/user/utils.lua
Normal file
15
lazyvim/.config/nvim/lua/user/utils.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
-- This file contains all custom functions for integrate external tools.
|
||||
|
||||
-- Meld for comparing and merging files
|
||||
local M = {}
|
||||
|
||||
function M.meld_diff(file1, file2)
|
||||
if not file1 or not file2 then
|
||||
print("Usage: :lua require'user.utils'.meld_diff('file1', 'file2')")
|
||||
return
|
||||
end
|
||||
local cmd = string.format("meld '%s' '%s' &", file1, file2)
|
||||
os.execute(cmd)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user