@@ -143,21 +143,21 @@ MiniPairs.config = {
143143 -- - <action> - one of "open", "close", "closeopen".
144144 -- - <pair> - two character string for pair to be used.
145145 -- By default pair is not inserted after `\`, quotes are not recognized by
146- -- <CR>, `'` does not insert pair after a letter.
146+ -- <CR>, `'` does not insert the pair after a letter.
147147 -- Only parts of tables can be tweaked (others will use these defaults).
148148 -- Supply `false` instead of table to not map particular key.
149149 mappings = {
150- [' (' ] = { action = ' open' , pair = ' ()' , neigh_pattern = ' [^\\ ]. ' },
151- [' [' ] = { action = ' open' , pair = ' []' , neigh_pattern = ' [^\\ ]. ' },
152- [' {' ] = { action = ' open' , pair = ' {}' , neigh_pattern = ' [^\\ ]. ' },
150+ [' (' ] = { action = ' open' , pair = ' ()' , neigh_pattern = ' ^ [^\\ ]' },
151+ [' [' ] = { action = ' open' , pair = ' []' , neigh_pattern = ' ^ [^\\ ]' },
152+ [' {' ] = { action = ' open' , pair = ' {}' , neigh_pattern = ' ^ [^\\ ]' },
153153
154- [' )' ] = { action = ' close' , pair = ' ()' , neigh_pattern = ' [^\\ ]. ' },
155- [' ]' ] = { action = ' close' , pair = ' []' , neigh_pattern = ' [^\\ ]. ' },
156- [' }' ] = { action = ' close' , pair = ' {}' , neigh_pattern = ' [^\\ ]. ' },
154+ [' )' ] = { action = ' close' , pair = ' ()' , neigh_pattern = ' ^ [^\\ ]' },
155+ [' ]' ] = { action = ' close' , pair = ' []' , neigh_pattern = ' ^ [^\\ ]' },
156+ [' }' ] = { action = ' close' , pair = ' {}' , neigh_pattern = ' ^ [^\\ ]' },
157157
158- [' "' ] = { action = ' closeopen' , pair = ' ""' , neigh_pattern = ' [^\\ ]. ' , register = { cr = false } },
159- [" '" ] = { action = ' closeopen' , pair = " ''" , neigh_pattern = ' [^%a\\ ]. ' , register = { cr = false } },
160- [' `' ] = { action = ' closeopen' , pair = ' ``' , neigh_pattern = ' [^\\ ]. ' , register = { cr = false } },
158+ [' "' ] = { action = ' closeopen' , pair = ' ""' , neigh_pattern = ' ^ [^\\ ]' , register = { cr = false } },
159+ [" '" ] = { action = ' closeopen' , pair = " ''" , neigh_pattern = ' ^ [^%a\\ ]' , register = { cr = false } },
160+ [' `' ] = { action = ' closeopen' , pair = ' ``' , neigh_pattern = ' ^ [^\\ ]' , register = { cr = false } },
161161 },
162162}
163163-- minidoc_afterlines_end
@@ -177,11 +177,11 @@ MiniPairs.config = {
177177--- @param pair_info table Table with pair information. Fields :
178178--- - <action> - one of "open" for |MiniPairs.open()|,
179179--- "close" for |MiniPairs.close()|, or "closeopen" for |MiniPairs.closeopen()|.
180- --- - <pair> - two character string to be used as argument for action function.
180+ --- - <pair> - two character string to be passed to an action function.
181181--- Can contain multibyte characters.
182- --- - <neigh_pattern> - optional 'two character' neighborhood pattern to be
183- --- used as argument for action function. Note: neighborhood might contain
184- --- multiple characters.
182+ --- - <neigh_pattern> - optional neighborhood pattern to be passed to an action
183+ --- function. Will be matched against two character neighborhood ( might
184+ --- contain multibyte characters) .
185185--- Default: `'..'` (no restriction from neighborhood).
186186--- - <register> - optional table with information about whether this pair will
187187--- be recognized by <BS> (in |MiniPairs.bs()|) and/or <CR> (in |MiniPairs.cr()|).
@@ -289,6 +289,8 @@ MiniPairs.open = function(pair, neigh_pattern)
289289 -- This can happen in a big file with tree-sitter highlighting enabled.
290290 H .with_temp_option (' lazyredraw' , true )
291291
292+ -- NOTE: Do not ensure no wildmenu because by the time arrow is executed
293+ -- wildmenu should already (usually) be hidden due to inserting `pair`
292294 return pair .. H .get_arrow_key (' left' )
293295end
294296
309311MiniPairs .close = function (pair , neigh_pattern )
310312 local close = H .get_close_char (pair )
311313 local move_right = not H .is_disabled () and H .neigh_match (neigh_pattern ) and H .get_neigh (' right' ) == close
312- return move_right and H .get_arrow_key (' right' ) or close
314+ return move_right and H .get_arrow_key (' right' , true ) or close
313315end
314316
315317--- Process "closeopen" symbols
327329--- @return string Keys performing " closeopen" action.
328330MiniPairs .closeopen = function (pair , neigh_pattern )
329331 local move_right = not H .is_disabled () and H .get_neigh (' right' ) == H .get_close_char (pair )
330- return move_right and H .get_arrow_key (' right' ) or MiniPairs .open (pair , neigh_pattern )
332+ return move_right and H .get_arrow_key (' right' , true ) or MiniPairs .open (pair , neigh_pattern )
331333end
332334
333335--- Process |<BS>|
@@ -416,7 +418,7 @@ H.keys = {
416418 bs = escape (' <BS>' ),
417419 cr = escape (' <CR>' ),
418420 del = escape (' <Del>' ),
419- keep_undo = escape (' <C-g>U ' ),
421+ ctrl_y = escape (' <C-y> ' ),
420422 -- Using left/right keys in insert mode breaks undo sequence and, more
421423 -- importantly, dot-repeat. To avoid this, use 'i_CTRL-G_U' mapping.
422424 -- Use `H.get_arrow_key()` for keys instead of direct from this table.
@@ -611,9 +613,17 @@ H.neigh_match = function(pattern) return H.get_neigh('whole'):find(pattern or ''
611613H .get_open_char = function (x ) return vim .fn .strcharpart (x , 0 , 1 ) end
612614H .get_close_char = function (x ) return vim .fn .strcharpart (x , 1 , 1 ) end
613615
614- H .get_arrow_key = function (key )
615- return vim .fn .mode () == ' i' and (key == ' right' and H .keys .right_undo or H .keys .left_undo )
616- or (key == ' right' and H .keys .right or H .keys .left )
616+ H .get_arrow_key = function (key , ensure_no_wildmenu )
617+ if vim .fn .mode () == ' i' then
618+ -- Take into account that `virtualedit=all` can go into inline virtual text
619+ H .with_temp_option (' virtualedit' , ' none' )
620+ return key == ' right' and H .keys .right_undo or H .keys .left_undo
621+ end
622+ local prefix = ' '
623+ -- In Command-line mode <Left> / <Right> act like <C-p> / <C-n> if wildmenu
624+ -- is shown. Make sure that arrow key moves cursor.
625+ if vim .fn .mode () == ' c' and ensure_no_wildmenu then prefix = vim .fn .wildmenumode () == 1 and H .keys .ctrl_y or ' ' end
626+ return prefix .. (key == ' right' and H .keys .right or H .keys .left )
617627end
618628
619629H .map = function (mode , lhs , rhs , opts )
0 commit comments