@@ -72,7 +72,7 @@ function M:_add(keys)
72
72
local plugins = self .active [keys .id ]
73
73
74
74
-- always delete the mapping immediately to prevent recursive mappings
75
- self :_del (keys , buf )
75
+ self :_del (keys )
76
76
self .active [keys .id ] = nil
77
77
78
78
if plugins then
@@ -81,6 +81,11 @@ function M:_add(keys)
81
81
Util .track ()
82
82
end
83
83
84
+ -- Create the real buffer-local mapping
85
+ if keys .ft then
86
+ self :_set (keys , buf )
87
+ end
88
+
84
89
local feed = vim .api .nvim_replace_termcodes (" <Ignore>" .. lhs , true , true , true )
85
90
-- insert instead of append the lhs
86
91
vim .api .nvim_feedkeys (feed , " i" , false )
@@ -93,6 +98,7 @@ function M:_add(keys)
93
98
})
94
99
end
95
100
101
+ -- buffer-local mappings
96
102
if keys .ft then
97
103
vim .api .nvim_create_autocmd (" FileType" , {
98
104
pattern = keys .ft ,
@@ -102,9 +108,7 @@ function M:_add(keys)
102
108
else
103
109
-- Only create the mapping if its managed by lazy
104
110
-- otherwise the plugin is supposed to manage it
105
- if keys [2 ] then
106
- self :_del (keys , event .buf )
107
- end
111
+ self :_set (keys , event .buf )
108
112
end
109
113
end ,
110
114
})
@@ -113,10 +117,22 @@ function M:_add(keys)
113
117
end
114
118
end
115
119
120
+ -- Delete a mapping and create the real global
121
+ -- mapping when needed
122
+ --- @param keys LazyKeys
123
+ function M :_del (keys )
124
+ pcall (vim .keymap .del , keys .mode , keys [1 ])
125
+ -- make sure to create global mappings when needed
126
+ -- buffer-local mappings are managed by lazy
127
+ if not keys .ft then
128
+ self :_set (keys )
129
+ end
130
+ end
131
+
132
+ -- Create a mapping if it is managed by lazy
116
133
--- @param keys LazyKeys
117
134
--- @param buf number ?
118
- function M :_del (keys , buf )
119
- pcall (vim .keymap .del , keys .mode , keys [1 ], { buffer = buf })
135
+ function M :_set (keys , buf )
120
136
if keys [2 ] then
121
137
local opts = M .opts (keys )
122
138
opts .buffer = buf
0 commit comments