diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-11-09 22:12:10 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-11-09 22:12:10 +0100 |
commit | 39642a92cbb324d747d18edc02de73e702b6a224 (patch) | |
tree | db45da1693522385a3ff303f9fb04a200c28288d /.config | |
parent | 5e858db56ee422ae5e8e786676afdd55609e9f65 (diff) |
nvim: Add tree-sitter-powered bindings for git rebasing
Diffstat (limited to '.config')
-rw-r--r-- | .config/nvim/after/ftplugin/gitrebase.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/.config/nvim/after/ftplugin/gitrebase.lua b/.config/nvim/after/ftplugin/gitrebase.lua new file mode 100644 index 0000000..3a81d62 --- /dev/null +++ b/.config/nvim/after/ftplugin/gitrebase.lua @@ -0,0 +1,30 @@ +local ts_utils = require('nvim-treesitter.ts_utils') + +local function map(lhs, rhs) + 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 or node:type() ~= 'operation' then + return + end + + local sr, sc, er, ec = node:child(0):range() + vim.api.nvim_buf_set_text(0, sr, sc, er, ec, { rhs }) + end, { + buffer = true, + noremap = true, + silent = true, + }) +end + +map('p', 'pick') +map('r', 'reword') +map('s', 'squash') +map('f', 'fixup') |