From e7b27047e22b14728ea7b0052316846a94e34439 Mon Sep 17 00:00:00 2001 From: PeteChu Date: Wed, 5 Apr 2023 15:16:52 +0700 Subject: [PATCH] Add descriptions to Harpoon and Cheat Sheet key mappings and include Dressing plugin in custom plugins --- after/plugin/harpoon.lua | 6 +++--- after/plugin/keymaps.lua | 3 +++ after/plugin/redir.vim | 36 ++++++++++++++++++++++++++++++++++++ lua/custom/plugins/init.lua | 3 ++- 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 after/plugin/redir.vim diff --git a/after/plugin/harpoon.lua b/after/plugin/harpoon.lua index 204b04a9..50b01072 100644 --- a/after/plugin/harpoon.lua +++ b/after/plugin/harpoon.lua @@ -1,8 +1,8 @@ local mark = require("harpoon.mark") local ui = require("harpoon.ui") -vim.keymap.set("n", "ha", mark.add_file) +vim.keymap.set("n", "ha", mark.add_file, { desc = "[H]arpoon [A]dd" }) vim.keymap.set("n", "", ui.toggle_quick_menu) -vim.keymap.set("n", "hn", function() ui.nav_next() end) -vim.keymap.set("n", "hp", function() ui.nav_prev() end) +vim.keymap.set("n", "hn", function() ui.nav_next() end, { desc = "[H]arpoon [N]ext" }) +vim.keymap.set("n", "hp", function() ui.nav_prev() end, { desc = "[H]arpoon [P]revious" }) diff --git a/after/plugin/keymaps.lua b/after/plugin/keymaps.lua index af0e9aee..be58cc8c 100644 --- a/after/plugin/keymaps.lua +++ b/after/plugin/keymaps.lua @@ -50,6 +50,9 @@ keymap('n', 'Y', "\"+Y", { desc = "[Y]ank to clipboard" }) -- Open folder in workspace in tmux session keymap("n", "op", "silent !tmux neww tmux-sessionizer", { desc = "[O]pen [P]roject" }) +-- Search cheat sheet +keymap("n", "ch", "silent !tmux neww tmux-cht.sh", { desc = "[C]heat [S]heet" }) + -- replace selected word in the file keymap("n", "R", [[:%s/\<\>//gI]], { desc = "[R]eplace words in the file" }) diff --git a/after/plugin/redir.vim b/after/plugin/redir.vim new file mode 100644 index 00000000..1aac8b4a --- /dev/null +++ b/after/plugin/redir.vim @@ -0,0 +1,36 @@ +function! Redir(cmd, rng, start, end) + for win in range(1, winnr('$')) + if getwinvar(win, 'scratch') + execute win . 'windo close' + endif + endfor + if a:cmd =~ '^!' + let cmd = a:cmd =~' %' + \ ? matchstr(substitute(a:cmd, ' %', ' ' . shellescape(escape(expand('%:p'), '\')), ''), '^!\zs.*') + \ : matchstr(a:cmd, '^!\zs.*') + if a:rng == 0 + let output = systemlist(cmd) + else + let joined_lines = join(getline(a:start, a:end), '\n') + let cleaned_lines = substitute(shellescape(joined_lines), "'\\\\''", "\\\\'", 'g') + let output = systemlist(cmd . " <<< $" . cleaned_lines) + endif + else + redir => output + execute a:cmd + redir END + let output = split(output, "\n") + endif + vnew + let w:scratch = 1 + setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile + call setline(1, output) +endfunction + +" This command definition includes -bar, so that it is possible to "chain" Vim commands. +" Side effect: double quotes can't be used in external commands +command! -nargs=1 -complete=command -bar -range Redir silent call Redir(, , , ) + +" This command definition doesn't include -bar, so that it is possible to use double quotes in external commands. +" Side effect: Vim commands can't be "chained". +command! -nargs=1 -complete=command -range Redir silent call Redir(, , , ) diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 36ea6762..974aa448 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -7,5 +7,6 @@ return { 'mbbill/undotree', 'famiu/bufdelete.nvim', 'ThePrimeagen/harpoon', - 'ThePrimeagen/vim-be-good' + 'ThePrimeagen/vim-be-good', + 'stevearc/dressing.nvim' }