forked from tanvirtin/vgit.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeymap.lua
More file actions
116 lines (95 loc) · 2.37 KB
/
Copy pathkeymap.lua
File metadata and controls
116 lines (95 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
local keymap = {}
function keymap.set(opts, callback)
opts = opts or {}
local key = opts.key
local mode = opts.mode
local desc = opts.desc
local mapping = opts.mapping
local silent = opts.silent == nil and true or opts.silent
local noremap = opts.noremap == nil and true or opts.noremap
if mapping then
if type(mapping) == 'table' then
key = mapping.key
desc = mapping.desc
else
key = mapping
end
end
if type(callback) == 'string' then
local command = callback
if not desc then
desc = 'VGit:' .. command
end
vim.api.nvim_set_keymap(mode, key, string.format('<Cmd>lua require("vgit").%s()<CR>', command), {
desc = desc,
silent = silent,
noremap = noremap,
})
return keymap
end
vim.keymap.set(mode, key, callback, {
desc = desc,
silent = silent,
noremap = noremap,
})
return keymap
end
function keymap.buffer_set(buffer, opts, callback)
opts = opts or {}
local key = opts.key
local mode = opts.mode
local desc = opts.desc
local mapping = opts.mapping
local silent = opts.silent == nil and true or opts.silent
local noremap = opts.noremap == nil and true or opts.noremap
if mapping then
if type(mapping) == 'table' then
key = mapping.key
desc = mapping.desc
else
key = mapping
end
end
vim.keymap.set(mode, key, callback, {
desc = desc,
silent = silent,
noremap = noremap,
nowait = true,
buffer = buffer.bufnr,
})
return keymap
end
function keymap.define(keymaps)
for commands, callback in pairs(keymaps) do
if type(callback) == 'table' then
local config = callback;
keymap.set(config, config.handler)
else
commands = vim.split(commands, ' ')
local config = {
mode = commands[1],
key = commands[2]
}
keymap.set(config, callback)
end
end
return keymap
end
function keymap.find(command)
local keybindings = {}
local modes = { 'n', 'i', 'v', 'x', 's', 'o', 't', 'c' }
for _, mode in ipairs(modes) do
local keymaps = vim.api.nvim_get_keymap(mode)
for _, binding in ipairs(keymaps) do
if binding.rhs and string.find(binding.rhs, command) then
table.insert(keybindings, {
mode = mode,
lhs = binding.lhs,
rhs = binding.rhs,
})
end
end
end
return keybindings
end
return keymap