From 0518e453308764aff0ec5c7c558d58a8774dc88a Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Thu, 10 Aug 2023 01:49:53 +0200 Subject: [PATCH] vim: move keymap for fugitive and neogit --- config/nvim/lua/fschauen/keymap.lua | 78 ++++++++++++------- config/nvim/lua/fschauen/plugins/fugitive.lua | 7 +- config/nvim/lua/fschauen/plugins/neogit.lua | 6 +- 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/config/nvim/lua/fschauen/keymap.lua b/config/nvim/lua/fschauen/keymap.lua index 3e0b33d..4a56e7a 100644 --- a/config/nvim/lua/fschauen/keymap.lua +++ b/config/nvim/lua/fschauen/keymap.lua @@ -1,3 +1,5 @@ +local M = {} + local diagnostic = require 'fschauen.diagnostic' local window = require 'fschauen.window' @@ -11,9 +13,7 @@ local toggle_relativenumber = function() vim.wo.number = vim.wo.relativenumber or vim.wo.number end -M = {} - -local base = { +local keymap = { -- better navigation for wrapped lines { 'j', 'gj' }, { 'k', 'gk' }, @@ -66,11 +66,15 @@ local base = { -- move to begin of line in command mode ( moves to end by default) { '', '', 'c' }, - -- navigate items in quickfix and location lists - { 'j', 'cnextzz' }, - { 'k', 'cpreviouszz' }, - { 'j', 'lnextzz' }, - { 'k', 'lpreviouszz' }, + -- more convenient way of entering normal mode from terminal mode + { [[]], [[]], 't' }, + + -- recall older/recent command-line from history + { '', '', 'c' }, + { '', '', 'c' }, + + -- quickly change background + { 'bg', [[let &background = &background ==? 'light' ? 'dark' : 'light']] }, -- navigate diagnostics { 'dj', diagnostic.goto_next }, @@ -79,6 +83,25 @@ local base = { { 'do', diagnostic.open_float }, { 'dh', diagnostic.hide }, + fugitive = { + { 'gg', ':Git ' }, + { 'gs', 'tab Git' }, + { 'gb', 'Git blame' } + }, + + neogit = { + { 'gn', 'Neogit' }, + }, + + -- disable highlight until next search + { 'h', 'nohlsearch' }, + + -- navigate items in quickfix and location lists + { 'j', 'cnextzz' }, + { 'k', 'cpreviouszz' }, + { 'j', 'lnextzz' }, + { 'k', 'lpreviouszz' }, + -- toggle quickfix and loclist { 'll', window.toggle_quickfix, desc = 'Toggle quickfix' }, { 'll', window.toggle_loclist, desc = 'Toggle loclist' }, @@ -92,32 +115,27 @@ local base = { { 'sl', 'set list! | set list?' }, { 'sw', 'set wrap! | set wrap?' }, { 'ss', 'set spell! | set spell?' }, - - -- quickly change background - { 'bg', [[let &background = &background ==? 'light' ? 'dark' : 'light']] }, - - -- disable highlight until next search - { 'h', 'nohlsearch' }, - - -- more convenient way of entering normal mode from terminal mode - { [[]], [[]], 't' }, - - -- recall older/recent command-line from history - { '', '', 'c' }, - { '', '', 'c' }, } -local keymap_set = vim.keymap.set -local map = function(opts) - local lhs, rhs, mode = opts[1], opts[2], opts[3] or 'n' - opts[1], opts[2], opts[3], opts.mode = nil, nil, nil, nil - opts.silent = opts.silent ~= false - keymap_set(mode, lhs, rhs, opts) +M.setup = function() + local keymap_set = vim.keymap.set + local set = function(opts) + local lhs, rhs, mode = opts[1], opts[2], opts[3] or 'n' + opts[1], opts[2], opts[3], opts.mode = nil, nil, nil, nil + opts.silent = opts.silent ~= false + keymap_set(mode, lhs, rhs, opts) + end + + for _, mapping in ipairs(keymap) do + set(mapping) + end end -M.setup = function() - vim.tbl_map(map, base) -end +setmetatable(M, { + __index = function (_, k) + return keymap[k] + end +}) return M diff --git a/config/nvim/lua/fschauen/plugins/fugitive.lua b/config/nvim/lua/fschauen/plugins/fugitive.lua index b943779..dbbd5bd 100644 --- a/config/nvim/lua/fschauen/plugins/fugitive.lua +++ b/config/nvim/lua/fschauen/plugins/fugitive.lua @@ -1,10 +1,5 @@ return { 'tpope/vim-fugitive', - - keys = { - { 'gg', ':Git ' }, - { 'gs', 'tab Git' }, - { 'gb', 'Git blame' } - }, + keys = require('fschauen.keymap').fugitive } diff --git a/config/nvim/lua/fschauen/plugins/neogit.lua b/config/nvim/lua/fschauen/plugins/neogit.lua index 7268434..d7e38b4 100644 --- a/config/nvim/lua/fschauen/plugins/neogit.lua +++ b/config/nvim/lua/fschauen/plugins/neogit.lua @@ -1,6 +1,6 @@ return { 'NeogitOrg/neogit', - + keys = require('fschauen.keymap').neogit, opts = { disable_hint = true, signs = { @@ -15,8 +15,4 @@ return { }, }, }, - - keys = { - { 'gn', 'Neogit' }, - }, }