From 19889f4cbf6a7019def9e85213c168e57633e679 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 26 Feb 2022 14:44:52 +0100 Subject: [PATCH] home: vim: use 'which-key' --- home/vim/after/plugin/mappings/fugitive.vim | 10 ---------- home/vim/after/plugin/mappings/fzf.vim | 16 ++++++++++++---- home/vim/after/plugin/mappings/git.vim | 20 ++++++++++++++++++++ home/vim/after/plugin/mappings/misc.vim | 13 +++++++++---- home/vim/after/plugin/mappings/qf.vim | 16 +++++++++++++--- 5 files changed, 54 insertions(+), 21 deletions(-) delete mode 100644 home/vim/after/plugin/mappings/fugitive.vim create mode 100644 home/vim/after/plugin/mappings/git.vim diff --git a/home/vim/after/plugin/mappings/fugitive.vim b/home/vim/after/plugin/mappings/fugitive.vim deleted file mode 100644 index 934f00e..0000000 --- a/home/vim/after/plugin/mappings/fugitive.vim +++ /dev/null @@ -1,10 +0,0 @@ -" Visual bindings for merging diffs as in normal mode -xnoremap dp :diffput -xnoremap do :diffget - -" Open status window -nnoremap gs :Gstatus -" Open diff view of current buffer: the up/left window is the current index -nnoremap gd :Gdiffsplit! -" Open current file log in new tab, populate its location list with history -nnoremap gl :spT:Gllog --follow -- %:p diff --git a/home/vim/after/plugin/mappings/fzf.vim b/home/vim/after/plugin/mappings/fzf.vim index 6bf4a44..fa98f0c 100644 --- a/home/vim/after/plugin/mappings/fzf.vim +++ b/home/vim/after/plugin/mappings/fzf.vim @@ -1,5 +1,13 @@ -" Only git-tracked files, Vim needs to be in a Git repository -nnoremap ff :GFiles +lua << EOF +local wk = require("which-key") -" Currently open buffers -nnoremap fb :Buffers +local keys = { + f = { + name = "Fuzzy finder", + b = { "Buffers", "Open buffers" }, + f = { "GFiles", "Git tracked files" }, + }, +} + +wk.register(keys, { prefix = "" }) +EOF diff --git a/home/vim/after/plugin/mappings/git.vim b/home/vim/after/plugin/mappings/git.vim new file mode 100644 index 0000000..677abd0 --- /dev/null +++ b/home/vim/after/plugin/mappings/git.vim @@ -0,0 +1,20 @@ +lua << EOF +local wk = require("which-key") + +local keys = { + d = { + name = "Merging diff hunks", + o = { "diffget", "Use this buffer's change", mode="x" }, + p = { "diffput", "Accept other buffer change", mode="x" }, + }, + ["g"] = { + name = "Git", + d = { "Gdiffsplit", "Current buffer diff" }, + l = { ":spT:Gllog --follow -- %:p", "Current buffer log" }, + m = { "(git-messenger)", "Current line blame" }, + s = { "Gstatus", "Status" }, + }, +} + +wk.register(keys) +EOF diff --git a/home/vim/after/plugin/mappings/misc.vim b/home/vim/after/plugin/mappings/misc.vim index fc2ed3d..d09410a 100644 --- a/home/vim/after/plugin/mappings/misc.vim +++ b/home/vim/after/plugin/mappings/misc.vim @@ -1,5 +1,10 @@ -" Run make silently, then skip the 'Press ENTER to continue' -noremap m :silent! :make! \| :redraw! +lua << EOF +local wk = require("which-key") -" Remove search-highlighting -noremap :nohls +local keys = { + m = { "silent! :make! | :redraw!", "Run make" }, + [""] = { "nohls", "Clear search highlight" }, +} + +wk.register(keys, { prefix = "" }) +EOF diff --git a/home/vim/after/plugin/mappings/qf.vim b/home/vim/after/plugin/mappings/qf.vim index 6c98759..e2eb8a7 100644 --- a/home/vim/after/plugin/mappings/qf.vim +++ b/home/vim/after/plugin/mappings/qf.vim @@ -1,3 +1,13 @@ -" Toggle quick-fix and location lists -nmap tf (qf_qf_toggle) -nmap tl (qf_loc_toggle) +lua << EOF +local wk = require("which-key") + +local keys = { + ["t"] = { + name = "Toggle", + f = { "(qf_qf_toggle)", "Toggle quickfix list" }, + l = { "(qf_loc_toggle)", "Toggle location list" }, + }, +} + +wk.register(keys, { prefix = "" }) +EOF