From 2f23034101520be0056a70a510830c4e80adee3b Mon Sep 17 00:00:00 2001 From: Felix Nehrke Date: Sun, 14 Sep 2025 20:18:35 +0200 Subject: [PATCH] Improve descriptions of key-mappings in neovim and align git-shortcuts I struggle to remember certain shortcuts sometimes. In these cases I rely on the "whichkey" plugin which shows a short description of for each possible keystroke in vim. Though I was lazy and didn't maintain these everywhere, so this change fixes that. Hopefully I can remeber all the keys better now. Furthermore this change contains some slight remappings regarding the git-keymappings. I used fugitive for most of that in the past, but I saw more potential using telescope in certain cases, especially navigating the history. --- .config/nvim/lua/plugins/fugitive.lua | 14 +++++---- .config/nvim/lua/plugins/goyo.lua | 2 +- .config/nvim/lua/plugins/nvim-telescope.lua | 33 +++++++++++++++------ .config/nvim/lua/plugins/treesl.lua | 12 ++++++-- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/.config/nvim/lua/plugins/fugitive.lua b/.config/nvim/lua/plugins/fugitive.lua index 0209dc6..bd26d19 100644 --- a/.config/nvim/lua/plugins/fugitive.lua +++ b/.config/nvim/lua/plugins/fugitive.lua @@ -1,13 +1,17 @@ +local cmd = function (cmd) + return function () vim.cmd(cmd) end +end + return { { "tpope/vim-fugitive", lazy = false, keys = { - { "gb", "G blame", desc = "Git blame" }, - { "gll", "G log --graph --format='%h (%ar) %s :: %aN <%aE>'", desc = "Git log" }, - { "glf", "G log --graph --format='%h (%ar) %s :: %aN <%aE>' %", desc = "Git log for current file" }, - { "glc", "Gclog -- %", desc = "Quicklist commits affecting the current file" }, - { "glh", "0Gclog -- %", desc = "Quicklist revisions of the current file" }, + { "gb", cmd("G blame"), desc = "Git blame" }, + { "gll", cmd("G log --graph --format='%h (%ar) %s :: %aN <%aE>'"), desc = "Git log" }, + { "glf", cmd("G log --graph --format='%h (%ar) %s :: %aN <%aE>' %"), desc = "Git log for current file" }, + { "glq", cmd("0Gclog -- %"), desc = "Quicklist revisions of the current file" }, + { "go", cmd("GBrowse"), desc = "Open file in Browser in Remote-Repo"} }, }, -- Github integration for :GBrowse diff --git a/.config/nvim/lua/plugins/goyo.lua b/.config/nvim/lua/plugins/goyo.lua index c3bc5ad..cf21555 100644 --- a/.config/nvim/lua/plugins/goyo.lua +++ b/.config/nvim/lua/plugins/goyo.lua @@ -10,7 +10,7 @@ return { require('lualine').hide() vim.cmd([[Goyo]]) vim.cmd([[Limelight!! 0.8]]) - end) + end, { desc = "Switch to goyo view" }) end -- "pocco81/true-zen.nvim", -- config = function () diff --git a/.config/nvim/lua/plugins/nvim-telescope.lua b/.config/nvim/lua/plugins/nvim-telescope.lua index 65c7060..e70ff53 100644 --- a/.config/nvim/lua/plugins/nvim-telescope.lua +++ b/.config/nvim/lua/plugins/nvim-telescope.lua @@ -18,14 +18,29 @@ return { local ts = require("telescope") ts.load_extension("fzf") local builtin = require("telescope.builtin") - vim.keymap.set("n", "", builtin.find_files) - vim.keymap.set("n", "b", "Telescope buffers") - vim.keymap.set("n", "fg", builtin.live_grep) - vim.keymap.set("n", "ff", builtin.oldfiles) - vim.keymap.set("n", "*", builtin.grep_string) - vim.keymap.set("n", "#", builtin.grep_string) - vim.keymap.set("n", "lf", builtin.git_bcommits) - vim.keymap.set("n", "ld", function () builtin.git_commits({ file_path = true, use_git_root = false }) end) - vim.keymap.set("n", "lb", builtin.git_branches) + vim.keymap.set("n", "", function () + builtin.find_files({ hidden = true }) + end, { desc = "Find files" }) + vim.keymap.set("n", "ff", function () + builtin.find_files({ no_ignore = true, hidden = true }) + end, { desc = "Find all files" }) + vim.keymap.set("n", "fb", function () vim.cmd("Telescope buffers") end, { desc = "Find buffers" }) + vim.keymap.set("n", "fg", builtin.live_grep, { desc = "Grep files" }) + vim.keymap.set("n", "fh", builtin.oldfiles, { desc = "Find recent files" }) + vim.keymap.set("n", "*", builtin.grep_string, { desc = "Find current word" }) + vim.keymap.set("n", "#", builtin.grep_string, { desc = "Find current word" }) + vim.keymap.set("n", "gh", function () + builtin.git_bcommits({ + git_command = {"git", "log", "--format=%h %s (%ar) %aN <%aE>", "--abbrev-commit"} + }) + end, { desc = "Git history of current file" }) + vim.keymap.set("n", "glh", function () + builtin.git_commits({ + file_path = true, + use_git_root = false, + git_command = {"git", "log", "--format=%h %s %Cgreen(%ar) %aN <%aE>", "--abbrev-commit", "--", "."} + }) + end, { desc = "Git history" }) + vim.keymap.set("n", "gs", builtin.git_branches, { desc = "Git branches" }) end, } diff --git a/.config/nvim/lua/plugins/treesl.lua b/.config/nvim/lua/plugins/treesl.lua index 38bd77a..067f2c4 100644 --- a/.config/nvim/lua/plugins/treesl.lua +++ b/.config/nvim/lua/plugins/treesl.lua @@ -1,8 +1,16 @@ +local cmd = function (cmd) + return function () vim.cmd(cmd) end +end + return { 'Wansmer/treesj', - keys = { 'm', 'j', 's' }, dependencies = { 'nvim-treesitter/nvim-treesitter' }, config = function() - require('treesj').setup({}) + require('treesj').setup({ + use_default_keymaps = false, + }) + vim.keymap.set("n", "bm", cmd("TSJToggle"), { desc = "Toggle expand/collapse block" }) + vim.keymap.set("n", "bj", cmd("TSJJoin"), { desc = "Collapse block" }) + vim.keymap.set("n", "bs", cmd("TSJSplit"), { desc = "Expand block" }) end, }