Compare commits

...

11 commits

Author SHA1 Message Date
Bruno BELANYI be0cc6b971 home: vime: tree-sitter: remove 'which-key'
All checks were successful
ci/woodpecker/push/check Pipeline was successful
The plug-in now has support for setting mapping descriptions by itself.
2024-07-19 11:36:27 +00:00
Bruno BELANYI 1fc64b57fd home: vim: tree-sitter: move mappings from 'after' 2024-07-19 11:36:27 +00:00
Bruno BELANYI 99a008d542 home: vim: telescope: move mappings from 'after' 2024-07-19 11:36:26 +00:00
Bruno BELANYI 9a6843a305 home: vim: signtoggle: use lua callbacks
Use `vim.opt` because this is a local option (i.e: similar to `set` it
defaults to setting it locally, `vim.opt_local` is not necessary).
2024-07-19 11:36:26 +00:00
Bruno BELANYI eb80441f49 home: vim: numbertoggle: use lua callbacks
Use `vim.opt` because those are local options (i.e: similar to `set` it
defaults to setting it locally, `vim.opt_local` is not necessary).
2024-07-19 11:36:26 +00:00
Bruno BELANYI d101ae56f2 home: vim: signtoggle: fix toggling
Don't know how I missed this for so long...
2024-07-19 11:36:26 +00:00
Bruno BELANYI 8792244419 home: vim: git: work around partial staging issue
See [1].

[1]: https://github.com/lewis6991/gitsigns.nvim/issues/929
2024-07-19 11:36:26 +00:00
Bruno BELANYI 33084169f2 home: vim: git: use 'partial' 2024-07-19 11:36:26 +00:00
Bruno BELANYI bcd9a31bb8 home: vim: lua: utils: add 'partial'
Love me some functional goodness.

This was taken from [1].

[1]: https://reddit.com/r/lua/comments/fh2go5
2024-07-19 11:36:26 +00:00
Bruno BELANYI 966934a8bc home: vim: git: use lua in hunk mappings 2024-07-19 11:36:26 +00:00
Bruno BELANYI 88e4d72366 home: vim: git: use lua in visual mappings
I thought the partial staging feature had broken, but it looks to be
unrelated [1].

[1]: https://github.com/lewis6991/gitsigns.nvim/issues/1088
2024-07-19 11:36:26 +00:00
8 changed files with 108 additions and 79 deletions

View file

@ -1,15 +0,0 @@
local wk = require("which-key")
local telescope_builtin = require("telescope.builtin")
local keys = {
f = {
name = "Fuzzy finder",
b = { telescope_builtin.buffers, "Open buffers" },
f = { telescope_builtin.git_files, "Git tracked files" },
F = { telescope_builtin.find_files, "Files" },
g = { telescope_builtin.live_grep, "Grep string" },
G = { telescope_builtin.grep_string, "Grep string under cursor" },
},
}
wk.register(keys, { prefix = "<leader>" })

View file

@ -1,30 +0,0 @@
local wk = require("which-key")
local motions = {
["]m"] = "Next method start",
["]M"] = "Next method end",
["]S"] = "Next statement start",
["]]"] = "Next class start",
["]["] = "Next class end",
["[m"] = "Previous method start",
["[M"] = "Previous method end",
["[S"] = "Previous statement start",
["[["] = "Previous class start",
["[]"] = "Previous class end",
}
local objects = {
["aa"] = "a parameter",
["ia"] = "inner parameter",
["ab"] = "a block",
["ib"] = "inner block",
["ac"] = "a class",
["ic"] = "inner class",
["af"] = "a function",
["if"] = "inner function",
["ak"] = "a comment",
["aS"] = "a statement",
}
wk.register(motions, { mode = "n" })
wk.register(objects, { mode = "o" })

View file

@ -48,4 +48,22 @@ M.list_lsp_clients = function(bufnr)
return names return names
end end
--- partially apply a function with given arguments
M.partial = function(f, ...)
local a = { ... }
local a_len = select("#", ...)
return function(...)
local tmp = { ... }
local tmp_len = select("#", ...)
-- Merge arg lists
for i = 1, tmp_len do
a[a_len + i] = tmp[i]
end
return f(unpack(a, 1, a_len + tmp_len))
end
end
return M return M

View file

@ -7,17 +7,28 @@ local numbertoggle = vim.api.nvim_create_augroup("numbertoggle", { clear = true
vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, { vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, {
pattern = "*", pattern = "*",
group = numbertoggle, group = numbertoggle,
command = "if &nu | setlocal rnu | endif", callback = function()
if vim.opt.number:get() then
vim.opt.relativenumber = true
end
end,
}) })
vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "WinLeave" }, { vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "WinLeave" }, {
pattern = "*", pattern = "*",
group = numbertoggle, group = numbertoggle,
command = "if &nu | setlocal nornu | endif", callback = function()
if vim.opt.number:get() then
vim.opt.relativenumber = false
end
end,
}) })
-- Never show the sign column in a terminal buffer -- Never show the sign column in a terminal buffer
vim.api.nvim_create_autocmd({ "TermOpen" }, { vim.api.nvim_create_autocmd({ "TermOpen" }, {
pattern = "*", pattern = "*",
group = numbertoggle, group = numbertoggle,
command = "setlocal nonu nornu", callback = function()
vim.opt.number = false
vim.opt.relativenumber = false
end,
}) })

View file

@ -1,17 +1,41 @@
local gitsigns = require("gitsigns") local gitsigns = require("gitsigns")
local utils = require("ambroisie.utils")
local wk = require("which-key") local wk = require("which-key")
--- Transform `f` into a function which acts on the current visual selection
local function make_visual(f)
return function()
local first = vim.fn.line("v")
local last = vim.fn.line(".")
f({ first, last })
end
end
local function nav_hunk(dir)
if vim.wo.diff then
local map = {
prev = "[c",
next = "]c",
}
vim.cmd.normal({ map[dir], bang = true })
else
gitsigns.nav_hunk(dir)
end
end
gitsigns.setup({ gitsigns.setup({
current_line_blame_opts = { current_line_blame_opts = {
-- Show the blame quickly -- Show the blame quickly
delay = 100, delay = 100,
}, },
-- Work-around for https://github.com/lewis6991/gitsigns.nvim/issues/929
signs_staged_enable = false,
}) })
local keys = { local keys = {
-- Navigation -- Navigation
["[c"] = { "&diff ? '[c' : '<cmd>Gitsigns prev_hunk<CR>'", "Previous hunk/diff", expr = true }, ["[c"] = { utils.partial(nav_hunk, "prev"), "Previous hunk/diff" },
["]c"] = { "&diff ? ']c' : '<cmd>Gitsigns next_hunk<CR>'", "Next hunk/diff", expr = true }, ["]c"] = { utils.partial(nav_hunk, "next"), "Next hunk/diff" },
-- Commands -- Commands
["<leader>g"] = { ["<leader>g"] = {
@ -20,7 +44,7 @@ local keys = {
b = { gitsigns.toggle_current_line_blame, "Toggle blame virtual text" }, b = { gitsigns.toggle_current_line_blame, "Toggle blame virtual text" },
d = { gitsigns.diffthis, "Diff buffer" }, d = { gitsigns.diffthis, "Diff buffer" },
-- stylua: ignore -- stylua: ignore
D = { function() gitsigns.diffthis("~") end, "Diff buffer against last commit" }, D = { utils.partial(gitsigns.diffthis, "~"), "Diff buffer against last commit" },
g = { "<cmd>Git<CR>", "Git status" }, g = { "<cmd>Git<CR>", "Git status" },
h = { gitsigns.toggle_deleted, "Show deleted hunks" }, h = { gitsigns.toggle_deleted, "Show deleted hunks" },
L = { "<cmd>:sp<CR><C-w>T:Gllog --follow -- %:p<CR>", "Current buffer log" }, L = { "<cmd>:sp<CR><C-w>T:Gllog --follow -- %:p<CR>", "Current buffer log" },
@ -43,13 +67,12 @@ local objects = {
local visual = { local visual = {
["ih"] = { gitsigns.select_hunk, "Git hunk" }, ["ih"] = { gitsigns.select_hunk, "Git hunk" },
-- Only the actual command can make use of the visual selection...
["<leader>g"] = { ["<leader>g"] = {
name = "Git", name = "Git",
p = { ":Gitsigns preview_hunk<CR>", "Preview selection" }, p = { gitsigns.preview_hunk, "Preview selection" },
r = { ":Gitsigns reset_hunk<CR>", "Restore selection" }, r = { make_visual(gitsigns.reset_hunk), "Restore selection" },
s = { ":Gitsigns stage_hunk<CR>", "Stage selection" }, s = { make_visual(gitsigns.stage_hunk), "Stage selection" },
u = { ":Gitsigns undo_stage_hunk<CR>", "Undo stage selection" }, u = { gitsigns.undo_stage_hunk, "Undo stage selection" },
}, },
} }

View file

@ -1,4 +1,6 @@
local telescope = require("telescope") local telescope = require("telescope")
local telescope_builtin = require("telescope.builtin")
local wk = require("which-key")
telescope.setup({ telescope.setup({
defaults = { defaults = {
@ -22,3 +24,16 @@ telescope.setup({
telescope.load_extension("fzf") telescope.load_extension("fzf")
telescope.load_extension("lsp_handlers") telescope.load_extension("lsp_handlers")
local keys = {
f = {
name = "Fuzzy finder",
b = { telescope_builtin.buffers, "Open buffers" },
f = { telescope_builtin.git_files, "Git tracked files" },
F = { telescope_builtin.find_files, "Files" },
g = { telescope_builtin.live_grep, "Grep string" },
G = { telescope_builtin.grep_string, "Grep string under cursor" },
},
}
wk.register(keys, { prefix = "<leader>" })

View file

@ -1,4 +1,5 @@
local ts_config = require("nvim-treesitter.configs") local ts_config = require("nvim-treesitter.configs")
ts_config.setup({ ts_config.setup({
highlight = { highlight = {
enable = true, enable = true,
@ -14,16 +15,16 @@ ts_config.setup({
-- Jump to matching text objects -- Jump to matching text objects
lookahead = true, lookahead = true,
keymaps = { keymaps = {
["aa"] = "@parameter.outer", ["aa"] = { query = "@parameter.outer", desc = "a parameter" },
["ia"] = "@parameter.inner", ["ia"] = { query = "@parameter.inner", desc = "inner parameter" },
["ab"] = "@block.outer", ["ab"] = { query = "@block.outer", desc = "a block" },
["ib"] = "@block.inner", ["ib"] = { query = "@block.inner", desc = "inner block" },
["ac"] = "@class.outer", ["ac"] = { query = "@class.outer", desc = "a class" },
["ic"] = "@class.inner", ["ic"] = { query = "@class.inner", desc = "inner class" },
["af"] = "@function.outer", ["af"] = { query = "@function.outer", desc = "a function" },
["if"] = "@function.inner", ["if"] = { query = "@function.inner", desc = "inner function" },
["ak"] = "@comment.outer", ["ak"] = { query = "@comment.outer", desc = "a comment" },
["aS"] = "@statement.outer", ["aS"] = { query = "@statement.outer", desc = "a statement" },
}, },
}, },
move = { move = {
@ -31,22 +32,22 @@ ts_config.setup({
-- Add to jump list -- Add to jump list
set_jumps = true, set_jumps = true,
goto_next_start = { goto_next_start = {
["]m"] = "@function.outer", ["]m"] = { query = "@function.outer", desc = "Next method start" },
["]S"] = "@statement.outer", ["]S"] = { query = "@statement.outer", desc = "Next statement start" },
["]]"] = "@class.outer", ["]]"] = { query = "@class.outer", desc = "Next class start" },
}, },
goto_next_end = { goto_next_end = {
["]M"] = "@function.outer", ["]M"] = { query = "@function.outer", desc = "Next method end" },
["]["] = "@class.outer", ["]["] = { query = "@class.outer", desc = "Next class end" },
}, },
goto_previous_start = { goto_previous_start = {
["[m"] = "@function.outer", ["[m"] = { query = "@function.outer", desc = "Previous method start" },
["[S"] = "@statement.outer", ["[S"] = { query = "@statement.outer", desc = "Previous statement start" },
["[["] = "@class.outer", ["[["] = { query = "@class.outer", desc = "Previous class start" },
}, },
goto_previous_end = { goto_previous_end = {
["[M"] = "@function.outer", ["[M"] = { query = "@function.outer", desc = "Previous method end" },
["[]"] = "@class.outer", ["[]"] = { query = "@class.outer", desc = "Previous class end" },
}, },
}, },
}, },

View file

@ -4,17 +4,23 @@ local signtoggle = vim.api.nvim_create_augroup("signtoggle", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "WinEnter" }, { vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained", "WinEnter" }, {
pattern = "*", pattern = "*",
group = signtoggle, group = signtoggle,
command = "setlocal signcolumn=yes", callback = function()
vim.opt.signcolumn = "yes"
end,
}) })
vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "WinLeave" }, { vim.api.nvim_create_autocmd({ "BufLeave", "FocusLost", "WinLeave" }, {
pattern = "*", pattern = "*",
group = signtoggle, group = signtoggle,
command = "setlocal signcolumn=yes", callback = function()
vim.opt.signcolumn = "no"
end,
}) })
-- Never show the sign column in a terminal buffer -- Never show the sign column in a terminal buffer
vim.api.nvim_create_autocmd({ "TermOpen" }, { vim.api.nvim_create_autocmd({ "TermOpen" }, {
pattern = "*", pattern = "*",
group = signtoggle, group = signtoggle,
command = "setlocal signcolumn=no", callback = function()
vim.opt.signcolumn = "no"
end,
}) })