mirror of
https://github.com/iofq/nvim.nix.git
synced 2026-01-23 08:55:16 -06:00
combine diffs
This commit is contained in:
parent
a004f24728
commit
c8d9279372
9 changed files with 93 additions and 76 deletions
|
|
@ -48,7 +48,7 @@ cmd('FileType', {
|
|||
local ns = vim.api.nvim_create_namespace('nvim.difftool.hl')
|
||||
vim.api.nvim_buf_clear_namespace(event.buf, ns, 0, -1)
|
||||
for i, item in ipairs(qf) do
|
||||
local path = vim.fn.fnamemodify(item.user_data.right, ':t')
|
||||
local path = vim.fn.fnamemodify(item.user_data.right, ':.')
|
||||
local hl = 'Added'
|
||||
if
|
||||
exec('git diff --quiet -- %s', path) ~= 0
|
||||
|
|
@ -98,6 +98,45 @@ cmd('BufWinEnter', {
|
|||
vim.cmd(string.format('%dcopen', math.min(10, #items)))
|
||||
end)
|
||||
end
|
||||
|
||||
local function get_hunks(bufnr)
|
||||
local conf_start = vim.fn.search('^<<<<<<<', 'bc')
|
||||
local base_start = vim.fn.search('^|||||||', 'W')
|
||||
local base_end = vim.fn.search('^=======', 'W')
|
||||
local conf_end = vim.fn.search('^>>>>>>>', 'W')
|
||||
|
||||
local left = vim.api.nvim_buf_get_lines(bufnr, conf_start, base_start - 1, false)
|
||||
local right = vim.api.nvim_buf_get_lines(bufnr, base_end, conf_end - 1, false)
|
||||
|
||||
return {
|
||||
start = conf_start,
|
||||
stop = conf_end,
|
||||
left = left,
|
||||
right = right,
|
||||
}
|
||||
end
|
||||
|
||||
local function apply_hunk(hunks, first)
|
||||
local result = {}
|
||||
if first == -1 then -- left first
|
||||
vim.list_extend(result, hunks.left)
|
||||
vim.list_extend(result, hunks.right)
|
||||
else
|
||||
vim.list_extend(result, hunks.right)
|
||||
vim.list_extend(result, hunks.left)
|
||||
end
|
||||
|
||||
-- apply hunk in place
|
||||
vim.api.nvim_buf_set_lines(0, hunks.start - 1, hunks.stop, false, result)
|
||||
end
|
||||
|
||||
-- "combine" mappings ala vscode's merge editor
|
||||
vim.keymap.set('n', '<leader>dl', function()
|
||||
apply_hunk(get_hunks(event.buf), -1)
|
||||
end, { buffer = event.buf })
|
||||
vim.keymap.set('n', '<leader>dr', function()
|
||||
apply_hunk(get_hunks(event.buf), 1)
|
||||
end, { buffer = event.buf })
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ vim.schedule(function()
|
|||
|
||||
require('mini.git').setup()
|
||||
map('n', '<leader>gb', '<Cmd>Git blame -- %<CR>')
|
||||
map('n', '<leader>go', function()
|
||||
return MiniGit.show_at_cursor()
|
||||
end)
|
||||
map('n', '<leader>go', MiniGit.show_at_cursor)
|
||||
|
||||
local jump = require('mini.jump2d')
|
||||
jump.setup {
|
||||
|
|
|
|||
|
|
@ -3,12 +3,7 @@ local map = vim.keymap.set
|
|||
require('mini.basics').setup { mappings = { windows = true } }
|
||||
require('mini.icons').setup()
|
||||
|
||||
require('dart').setup {
|
||||
tabline = {
|
||||
icons = false,
|
||||
label_marked_fg = 'cyan',
|
||||
},
|
||||
}
|
||||
require('dart').setup {}
|
||||
|
||||
require('snacks').setup {
|
||||
bigfile = { enabled = true },
|
||||
|
|
@ -65,12 +60,6 @@ vim.schedule(function()
|
|||
require('nvim-treesitter-textobjects').setup()
|
||||
require('nvim-autopairs').setup()
|
||||
|
||||
require('refactoring').setup()
|
||||
map('n', '<leader>rr', require('refactoring').select_refactor)
|
||||
map('n', '<leader>rv', function()
|
||||
require('refactoring').refactor('Inline Variable')
|
||||
end)
|
||||
|
||||
require('quicker').setup()
|
||||
map('n', '<leader>qf', function()
|
||||
require('quicker').toggle { max_height = 20 }
|
||||
|
|
@ -82,7 +71,6 @@ vim.schedule(function()
|
|||
json = { 'jq' },
|
||||
lua = { 'stylua' },
|
||||
python = { 'ruff' },
|
||||
nix = { 'nixfmt' },
|
||||
fish = { 'fish_indent' },
|
||||
['*'] = { 'trim_whitespace' },
|
||||
},
|
||||
|
|
@ -128,7 +116,7 @@ vim.schedule(function()
|
|||
sources = {
|
||||
default = { 'lsp', 'path', 'snippets', 'ripgrep', 'buffer' },
|
||||
providers = {
|
||||
lsp = { fallbacks = {} }, -- include buffer even when LSP is active
|
||||
lsp = { fallbacks = {}, async = true }, -- include buffer even when LSP is active
|
||||
path = { opts = { get_cwd = vim.fn.getcwd } }, -- use nvim pwd instead of current file pwd
|
||||
ripgrep = {
|
||||
module = 'blink-ripgrep',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue