From eb0dd08f7059a4edf7b0f4440f46de6e673b3460 Mon Sep 17 00:00:00 2001 From: Andy Teijelo Date: Thu, 10 Nov 2022 11:01:12 -0500 Subject: [PATCH] don't fail keymaps if plugins aren't installed --- lua/user/keymaps.lua | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lua/user/keymaps.lua b/lua/user/keymaps.lua index 3c1cb82..b3ac209 100644 --- a/lua/user/keymaps.lua +++ b/lua/user/keymaps.lua @@ -129,15 +129,27 @@ keymap("i", "", "gk", opts) -- vim.keymap.set('n', 'hb', function() gs.blame_line{full=false} end, opts) -- vim.keymap.set('n', 'hB', function() gs.blame_line{full=true} end, opts) -local wk = require("which-key") -local gs = require("gitsigns") -wk.register({ - g = { - name = "gitsigns", - p = { "Gitsigns preview_hunk", "Preview hunk" }, - b = { function() gs.blame_line{full=false} end, "Blame line (short)" }, - B = { function() gs.blame_line{full=true} end, "Blame line (full)" } - }, - prefix = "" -}) +local function otherkeymaps() + local ok + local wk + local gs + ok, wk = pcall(require, "which-key") + if not ok then + return + end + ok, gs = pcall(require, "gitsigns") + if not ok then + return + end + wk.register({ + g = { + name = "gitsigns", + p = { "Gitsigns preview_hunk", "Preview hunk" }, + b = { function() gs.blame_line{full=false} end, "Blame line (short)" }, + B = { function() gs.blame_line{full=true} end, "Blame line (full)" } + }, + prefix = "" + }) +end +otherkeymaps()