summaryrefslogtreecommitdiff
path: root/.config/nvim/after/ftplugin/gitrebase.lua
blob: 00ee21a8f57228a94869f717ac1dc9f9027ea421 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
local function map(lhs, rhs)
	local ts_utils = require('nvim-treesitter.ts_utils')
	vim.keymap.set('n', lhs, function()
		local node = ts_utils.get_node_at_cursor()
		if node == nil then
			error('No tree-sitter parser found.')
		end

		while node ~= nil and node:type() ~= 'operation' do
			node = node:parent()
		end

		if node ~= nil then
			local sr, sc, er, ec = node:child(0):range()
			vim.api.nvim_buf_set_text(0, sr, sc, er, ec, { rhs })
		end
	end, {
		buffer = true,
		noremap = true,
		silent = true,
	})
end

map('d', 'drop')
map('f', 'fixup')
map('p', 'pick')
map('r', 'reword')
map('s', 'squash')