11local M = {}
2- local uv = vim .uv
2+ local uv = vim .uv or vim . loop
33
44M .waiting = false
55
66local settings = {
77 timeout = vim .o .timeoutlen ,
8+ default_mappings = true ,
89 mappings = {
910 i = {
10- -- first_key[s]
11+ -- first_key[s]
1112 j = {
12- -- second_key[s]
13+ -- second_key[s]
1314 k = " <Esc>" ,
1415 j = " <Esc>" ,
1516 },
@@ -51,9 +52,9 @@ local function unmap_keys()
5152end
5253
5354-- WIP: move this into recorder.lua ?
54- -- When a first_key is pressed, `recorded_key` is set to it
55+ -- When a first_key is pressed, `recorded_key` is set to it
5556-- (e.g. if jk is a mapping, when 'j' is pressed, `recorded_key` is set to 'j')
56- local recorded_key = nil
57+ local recorded_key = nil
5758local bufmodified = nil
5859local timeout_timer = uv .new_timer ()
5960local has_recorded = false -- See `vim.on_key` below
@@ -63,7 +64,7 @@ local function record_key(key)
6364 end
6465 bufmodified = vim .bo .modified
6566 recorded_key = key
66- has_recorded = true
67+ has_recorded = true
6768 M .waiting = true
6869 timeout_timer :start (settings .timeout , 0 , function ()
6970 M .waiting = false
@@ -96,7 +97,7 @@ local function map_keys()
9697 return first_key
9798 end , map_opts )
9899 end
99- for first_key , second_keys in pairs (first_keys ) do
100+ for _ , second_keys in pairs (first_keys ) do
100101 for second_key , mapping in pairs (second_keys ) do
101102 if not mapping then
102103 goto continue
@@ -110,7 +111,12 @@ local function map_keys()
110111 end
111112 -- If a key was recorded, but it isn't the first_key for second_key, record second_key(second_key might be a first_key for another sequence)
112113 -- Or if the recorded_key was just a second_key
113- if not (first_keys [recorded_key ] and first_keys [recorded_key ][second_key ]) then
114+ if
115+ not (
116+ first_keys [recorded_key ]
117+ and first_keys [recorded_key ][second_key ]
118+ )
119+ then
114120 record_key (second_key )
115121 return second_key
116122 end
134140
135141function M .setup (update )
136142 unmap_keys ()
143+ if update and update .default_mappings == false then
144+ settings .mappings = {}
145+ end
137146 settings = vim .tbl_deep_extend (" force" , settings , update or {})
138147 if settings .keys or settings .clear_empty_lines then
139148 vim .notify (
0 commit comments