robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesfeat(input)!: CmdAtom event #4129764a301184e

master
51.1 KiB1888 linesraw
1" Tests for mappings and abbreviations
2
3source shared.vim
4source check.vim
5source screendump.vim
6source term_util.vim
7
8func Test_abbreviation()
9  new
10
11  " abbreviation with 0x80 (full-id)
12  inoreab чкпр   vim
13  call feedkeys("Goчкпр \<Esc>", "xt")
14  call assert_equal('vim ', getline('$'))
15  iunab чкпр
16
17  " abbreviation with 0x80 (non-id)
18  inoreab abc⁀ abc^
19  inoreab ⁀ ^
20  call feedkeys("Goabc⁀ def⁀ ⁀ \<Esc>", "xt")
21  call assert_equal('abc^ def⁀ ^ ', getline('$'))
22  iunab abc⁀
23  iunab ⁀
24
25  " abbreviation with 0x9b (non-id)
26  inoreab abc; abc;
27  inoreab ; ;
28  call feedkeys("Goabc; def; ; \<Esc>", "xt")
29  call assert_equal('abc; def; ; ', getline('$'))
30  iunab abc;
31  iunab ;
32
33  " abbreviation with composing chars (end-id)
34  inoreab ..ã a^~
35  inoreab ..β̃ β^~
36  inoreab ..π̃ π^~
37  inoreab ..Λ̃ Λ^~
38  call feedkeys("Go..ã ..β̃ ..π̃ ..Λ̃ \<Esc>", "xt")
39  call assert_equal('a^~ β^~ π^~ Λ^~ ', getline('$'))
40  iunab ..ã
41  iunab ..β̃
42  iunab ..π̃
43  iunab ..Λ̃
44
45  bwipe!
46endfunc
47
48func Test_abbreviation_with_noremap()
49  nnoremap <F2> :echo "cheese"
50  cabbr cheese xxx
51  call feedkeys(":echo \"cheese\"\<C-B>\"\<CR>", 'tx')
52  call assert_equal('"echo "xxx"', @:)
53  call feedkeys("\<F2>\<C-B>\"\<CR>", 'tx')
54  call assert_equal('"echo "cheese"', @:)
55  nnoremap <F2> :echo "cheese<C-]>"
56  call feedkeys("\<F2>\<C-B>\"\<CR>", 'tx')
57  call assert_equal('"echo "xxx"', @:)
58  nunmap <F2>
59  cunabbr cheese
60
61  new
62  inoremap <buffer> ( <C-]>()
63  iabbr <buffer> fnu fun
64  call feedkeys("ifnu(", 'tx')
65  call assert_equal('fun()', getline(1))
66  bwipe!
67endfunc
68
69func Test_abclear()
70  abbrev foo foobar
71  iabbrev fooi foobari
72  cabbrev fooc foobarc
73  call assert_equal("\n\n"
74        \        .. "c  fooc          foobarc\n"
75        \        .. "i  fooi          foobari\n"
76        \        .. "!  foo           foobar", execute('abbrev'))
77
78  iabclear
79  call assert_equal("\n\n"
80        \        .. "c  fooc          foobarc\n"
81        \        .. "c  foo           foobar", execute('abbrev'))
82  abbrev foo foobar
83  iabbrev fooi foobari
84
85  cabclear
86  call assert_equal("\n\n"
87        \        .. "i  fooi          foobari\n"
88        \        .. "i  foo           foobar", execute('abbrev'))
89  abbrev foo foobar
90  cabbrev fooc foobarc
91
92  abclear
93  call assert_equal("\n\nNo abbreviation found", execute('abbrev'))
94  call assert_fails('%abclear', 'E481:')
95endfunc
96
97func Test_abclear_buffer()
98  abbrev foo foobar
99  new X1
100  abbrev <buffer> foo1 foobar1
101  new X2
102  abbrev <buffer> foo2 foobar2
103
104  call assert_equal("\n\n"
105        \        .. "!  foo2         @foobar2\n"
106        \        .. "!  foo           foobar", execute('abbrev'))
107
108  abclear <buffer>
109  call assert_equal("\n\n"
110        \        .. "!  foo           foobar", execute('abbrev'))
111
112  b X1
113  call assert_equal("\n\n"
114        \        .. "!  foo1         @foobar1\n"
115        \        .. "!  foo           foobar", execute('abbrev'))
116  abclear <buffer>
117  call assert_equal("\n\n"
118        \        .. "!  foo           foobar", execute('abbrev'))
119
120  abclear
121  call assert_equal("\n\nNo abbreviation found", execute('abbrev'))
122
123  %bwipe
124endfunc
125
126func Test_map_ctrl_c_insert()
127  " mapping of ctrl-c in Insert mode
128  set cpo-=< cpo-=k
129  inoremap <c-c> <ctrl-c>
130  cnoremap <c-c> dummy
131  cunmap <c-c>
132  call feedkeys("GoTEST2: CTRL-C |\<*C-C>A|\<Esc>", "xt")
133  call assert_equal('TEST2: CTRL-C |<ctrl-c>A|', getline('$'))
134  unmap! <c-c>
135  set nomodified
136endfunc
137
138func Test_map_ctrl_c_visual()
139  " mapping of ctrl-c in Visual mode
140  vnoremap <c-c> :<C-u>$put ='vmap works'
141  call feedkeys("GV\<*C-C>\<CR>", "xt")
142  call assert_equal('vmap works', getline('$'))
143  vunmap <c-c>
144  set nomodified
145endfunc
146
147func Test_map_langmap()
148  if !has('langmap')
149    return
150  endif
151
152  " check langmap applies in normal mode
153  set langmap=+- nolangremap
154  new
155  call setline(1, ['a', 'b', 'c'])
156  2
157  call assert_equal('b', getline('.'))
158  call feedkeys("+", "xt")
159  call assert_equal('a', getline('.'))
160
161  " check no remapping
162  map x +
163  2
164  call feedkeys("x", "xt")
165  call assert_equal('c', getline('.'))
166
167  " check with remapping
168  set langremap
169  2
170  call feedkeys("x", "xt")
171  call assert_equal('a', getline('.'))
172
173  unmap x
174  bwipe!
175
176  " 'langnoremap' follows 'langremap' and vice versa
177  set langremap
178  set langnoremap
179  call assert_equal(0, &langremap)
180  set langremap
181  call assert_equal(0, &langnoremap)
182  set nolangremap
183  call assert_equal(1, &langnoremap)
184
185  " check default values
186  set langnoremap&
187  call assert_equal(1, &langnoremap)
188  call assert_equal(0, &langremap)
189  set langremap&
190  call assert_equal(1, &langnoremap)
191  call assert_equal(0, &langremap)
192
193  " langmap should not apply in insert mode, 'langremap' doesn't matter
194  set langmap=+{ nolangremap
195  call feedkeys("Go+\<Esc>", "xt")
196  call assert_equal('+', getline('$'))
197  set langmap=+{ langremap
198  call feedkeys("Go+\<Esc>", "xt")
199  call assert_equal('+', getline('$'))
200
201  " langmap used for register name in insert mode.
202  call setreg('a', 'aaaa')
203  call setreg('b', 'bbbb')
204  call setreg('c', 'cccc')
205  set langmap=ab langremap
206  call feedkeys("Go\<C-R>a\<Esc>", "xt")
207  call assert_equal('bbbb', getline('$'))
208  call feedkeys("Go\<C-R>\<C-R>a\<Esc>", "xt")
209  call assert_equal('bbbb', getline('$'))
210  " mapping does not apply
211  imap c a
212  call feedkeys("Go\<C-R>c\<Esc>", "xt")
213  call assert_equal('cccc', getline('$'))
214  imap a c
215  call feedkeys("Go\<C-R>a\<Esc>", "xt")
216  call assert_equal('bbbb', getline('$'))
217
218  " langmap should not apply in Command-line mode
219  set langmap=+{ nolangremap
220  call feedkeys(":call append(line('$'), '+')\<CR>", "xt")
221  call assert_equal('+', getline('$'))
222
223  iunmap a
224  iunmap c
225  set nomodified
226endfunc
227
228func Test_map_feedkeys()
229  " issue #212 (feedkeys insert mapping at current position)
230  nnoremap . :call feedkeys(".", "in")<cr>
231  call setline('$', ['a b c d', 'a b c d'])
232  $-1
233  call feedkeys("0qqdw.ifoo\<Esc>qj0@q\<Esc>", "xt")
234  call assert_equal(['fooc d', 'fooc d'], getline(line('$') - 1, line('$')))
235  nunmap .
236  set nomodified
237endfunc
238
239func Test_map_cursor()
240  " <c-g>U<cursor> works only within a single line
241  imapclear
242  imap ( ()<c-g>U<left>
243  call feedkeys("G2o\<Esc>ki\<CR>Test1: text with a (here some more text\<Esc>k.", "xt")
244  call assert_equal('Test1: text with a (here some more text)', getline(line('$') - 2))
245  call assert_equal('Test1: text with a (here some more text)', getline(line('$') - 1))
246
247  " test undo
248  call feedkeys("G2o\<Esc>ki\<CR>Test2: text wit a (here some more text [und undo]\<C-G>u\<Esc>k.u", "xt")
249  call assert_equal('', getline(line('$') - 2))
250  call assert_equal('Test2: text wit a (here some more text [und undo])', getline(line('$') - 1))
251  set nomodified
252  imapclear
253endfunc
254
255func Test_map_cursor_ctrl_gU()
256  " <c-g>U<cursor> works only within a single line
257  nnoremap c<* *Ncgn<C-r>"<C-G>U<S-Left>
258  call setline(1, ['foo', 'foobar', '', 'foo'])
259  call cursor(1,2)
260  call feedkeys("c<*PREFIX\<esc>.", 'xt')
261  call assert_equal(['PREFIXfoo', 'foobar', '', 'PREFIXfoo'], getline(1,'$'))
262  " break undo manually
263  set ul=1000
264  exe ":norm! uu"
265  call assert_equal(['foo', 'foobar', '', 'foo'], getline(1,'$'))
266
267  " Test that it does not work if the cursor moves to the previous line
268  " 2 times <S-Left> move to the previous line
269  nnoremap c<* *Ncgn<C-r>"<C-G>U<S-Left><C-G>U<S-Left>
270  call setline(1, ['', ' foo', 'foobar', '', 'foo'])
271  call cursor(2,3)
272  call feedkeys("c<*PREFIX\<esc>.", 'xt')
273  call assert_equal(['PREFIXPREFIX', ' foo', 'foobar', '', 'foo'], getline(1,'$'))
274  nmapclear
275endfunc
276
277
278" This isn't actually testing a mapping, but similar use of CTRL-G U as above.
279func Test_break_undo()
280  set whichwrap=<,>,[,]
281  call feedkeys("G4o2k", "xt")
282  " Nvim: "." re-executes the whole insert session, including the (wrapping)
283  " CTRL-G U <Right>, instead of only the text typed after it.
284  exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>."
285  call assert_equal('Test3: text with a (parenthesis here', getline(line('$') - 3))
286  call assert_equal('new line hereTest3: text with a (parenthesis here', getline(line('$') - 2))
287  call assert_equal('new line here', getline(line('$') - 1))
288  set nomodified
289endfunc
290
291func Test_map_meta_quotes()
292  imap <M-"> foo
293  call feedkeys("Go-\<*M-\">-\<Esc>", "xt")
294  call assert_equal("-foo-", getline('$'))
295  set nomodified
296  iunmap <M-">
297endfunc
298
299func Test_map_meta_multibyte()
300  imap <M-á> foo
301  call assert_match('i  <M-á>\s*foo', execute('imap'))
302  iunmap <M-á>
303endfunc
304
305func Test_map_super_quotes()
306  if "\<D-j>"[-1:] == '>'
307    throw 'Skipped: <D- modifier not supported'
308  endif
309
310  imap <D-"> foo
311  call feedkeys("Go-\<*D-\">-\<Esc>", "xt")
312  call assert_equal("-foo-", getline('$'))
313  set nomodified
314  iunmap <D-">
315endfunc
316
317func Test_map_super_multibyte()
318  if "\<D-j>"[-1:] == '>'
319    throw 'Skipped: <D- modifier not supported'
320  endif
321
322  imap <D-á> foo
323  call assert_match('i  <D-á>\s*foo', execute('imap'))
324  iunmap <D-á>
325endfunc
326
327func Test_abbr_after_line_join()
328  new
329  abbr foo bar
330  set backspace=indent,eol,start
331  exe "normal o\<BS>foo "
332  call assert_equal("bar ", getline(1))
333  bwipe!
334  unabbr foo
335  set backspace&
336endfunc
337
338func Test_map_timeout()
339  if !has('timers')
340    return
341  endif
342  nnoremap aaaa :let got_aaaa = 1<CR>
343  nnoremap bb :let got_bb = 1<CR>
344  nmap b aaa
345  new
346  func ExitInsert(timer)
347    let g:line = getline(1)
348    call feedkeys("\<Esc>", "t")
349  endfunc
350  set timeout timeoutlen=200
351  let timer = timer_start(300, 'ExitInsert')
352  " After the 'b' Vim waits for another character to see if it matches 'bb'.
353  " When it times out it is expanded to "aaa", but there is no wait for
354  " "aaaa".  Can't check that reliably though.
355  call feedkeys("b", "xt!")
356  call assert_equal("aa", g:line)
357  call assert_false(exists('got_aaa'))
358  call assert_false(exists('got_bb'))
359
360  bwipe!
361  nunmap aaaa
362  nunmap bb
363  nunmap b
364  set timeoutlen&
365  delfunc ExitInsert
366  call timer_stop(timer)
367endfunc
368
369func Test_map_timeout_with_timer_interrupt()
370  CheckFeature job
371  CheckFeature timers
372  let g:test_is_flaky = 1
373
374  " Confirm the timer invoked in exit_cb of the job doesn't disturb mapped key
375  " sequence.
376  new
377  let g:val = 0
378  nnoremap \12 :let g:val = 1<CR>
379  nnoremap \123 :let g:val = 2<CR>
380  set timeout timeoutlen=200
381
382  func ExitCb(job, status)
383    let g:timer = timer_start(1, {-> feedkeys("3\<Esc>", 't')})
384  endfunc
385
386  call job_start([&shell, &shellcmdflag, 'echo'], {'exit_cb': 'ExitCb'})
387  call feedkeys('\12', 'xt!')
388  call assert_equal(2, g:val)
389
390  bwipe!
391  nunmap \12
392  nunmap \123
393  set timeoutlen&
394  call WaitFor({-> exists('g:timer')})
395  call timer_stop(g:timer)
396  unlet g:timer
397  unlet g:val
398  delfunc ExitCb
399endfunc
400
401func Test_cabbr_visual_mode()
402  cabbr s su
403  call feedkeys(":s \<c-B>\"\<CR>", 'itx')
404  call assert_equal('"su ', getreg(':'))
405  call feedkeys(":'<,'>s \<c-B>\"\<CR>", 'itx')
406  let expected = '"'. "'<,'>su "
407  call assert_equal(expected, getreg(':'))
408  call feedkeys(":  '<,'>s \<c-B>\"\<CR>", 'itx')
409  let expected = '"  '. "'<,'>su "
410  call assert_equal(expected, getreg(':'))
411  call feedkeys(":'a,'bs \<c-B>\"\<CR>", 'itx')
412  let expected = '"'. "'a,'bsu "
413  call assert_equal(expected, getreg(':'))
414  cunabbr s
415endfunc
416
417func Test_abbreviation_CR()
418  new
419  func Eatchar(pat)
420    let c = nr2char(getchar(0))
421    return (c =~ a:pat) ? '' : c
422  endfunc
423  iabbrev <buffer><silent> ~~7 <c-r>=repeat('~', 7)<CR><c-r>=Eatchar('\s')<cr>
424  call feedkeys("GA~~7 \<esc>", 'xt')
425  call assert_equal('~~~~~~~', getline('$'))
426  %d
427  call feedkeys("GA~~7\<cr>\<esc>", 'xt')
428  call assert_equal(['~~~~~~~', ''], getline(1,'$'))
429  delfunc Eatchar
430  bw!
431endfunc
432
433func Test_motionforce_omap()
434  func GetCommand()
435    let g:m=mode(1)
436    let [g:lnum1, g:col1] = searchpos('-', 'Wb')
437    if g:lnum1 == 0
438        return "\<Esc>"
439    endif
440    let [g:lnum2, g:col2] = searchpos('-', 'W')
441    if g:lnum2 == 0
442        return "\<Esc>"
443    endif
444    return ":call Select()\<CR>"
445  endfunc
446  func Select()
447    call cursor([g:lnum1, g:col1])
448    exe "normal! 1 ". (strlen(g:m) == 2 ? 'v' : g:m[2])
449    call cursor([g:lnum2, g:col2])
450    execute "normal! \<BS>"
451  endfunc
452  new
453  onoremap <buffer><expr> i- GetCommand()
454  " 1) default omap mapping
455  %d_
456  call setline(1, ['aaa - bbb', 'x', 'ddd - eee'])
457  call cursor(2, 1)
458  norm di-
459  call assert_equal('no', g:m)
460  call assert_equal(['aaa -- eee'], getline(1, '$'))
461  " 2) forced characterwise operation
462  %d_
463  call setline(1, ['aaa - bbb', 'x', 'ddd - eee'])
464  call cursor(2, 1)
465  norm dvi-
466  call assert_equal('nov', g:m)
467  call assert_equal(['aaa -- eee'], getline(1, '$'))
468  " 3) forced linewise operation
469  %d_
470  call setline(1, ['aaa - bbb', 'x', 'ddd - eee'])
471  call cursor(2, 1)
472  norm dVi-
473  call assert_equal('noV', g:m)
474  call assert_equal([''], getline(1, '$'))
475  " 4) forced blockwise operation
476  %d_
477  call setline(1, ['aaa - bbb', 'x', 'ddd - eee'])
478  call cursor(2, 1)
479  exe "norm d\<C-V>i-"
480  call assert_equal("no\<C-V>", g:m)
481  call assert_equal(['aaabbb', 'x', 'dddeee'], getline(1, '$'))
482  bwipe!
483  delfunc Select
484  delfunc GetCommand
485endfunc
486
487func Test_error_in_map_expr()
488  " Unlike CheckRunVimInTerminal this does work in a win32 console
489  CheckFeature terminal
490  if has('win32') && has('gui_running')
491    throw 'Skipped: cannot run Vim in a terminal window'
492  endif
493
494  let lines =<< trim [CODE]
495  func Func()
496    " fail to create list
497    let x = [
498  endfunc
499  nmap <expr> ! Func()
500  set updatetime=50
501  [CODE]
502  call writefile(lines, 'Xtest.vim')
503
504  let buf = term_start(GetVimCommandCleanTerm() .. ' -S Xtest.vim', {'term_rows': 8})
505  let job = term_getjob(buf)
506  call WaitForAssert({-> assert_notequal('', term_getline(buf, 8))})
507
508  " GC must not run during map-expr processing, which can make Vim crash.
509  call term_sendkeys(buf, '!')
510  call TermWait(buf, 50)
511  call term_sendkeys(buf, "\<CR>")
512  call TermWait(buf, 50)
513  call assert_equal('run', job_status(job))
514
515  call term_sendkeys(buf, ":qall!\<CR>")
516  call WaitFor({-> job_status(job) ==# 'dead'})
517  if has('unix')
518    call assert_equal('', job_info(job).termsig)
519  endif
520
521  call delete('Xtest.vim')
522  exe buf .. 'bwipe!'
523endfunc
524
525func Test_list_mappings()
526  " Remove default mappings
527  imapclear
528
529  " reset 'isident' to check it isn't used
530  set isident=
531  inoremap <C-m> CtrlM
532  inoremap <A-S> AltS
533  inoremap <S-/> ShiftSlash
534  set isident&
535  call assert_equal([
536	\ 'i  <S-/>       * ShiftSlash',
537	\ 'i  <M-S>       * AltS',
538	\ 'i  <C-M>       * CtrlM',
539	\], execute('imap')->trim()->split("\n"))
540  iunmap <C-M>
541  iunmap <A-S>
542  call assert_equal(['i  <S-/>       * ShiftSlash'], execute('imap')->trim()->split("\n"))
543  iunmap <S-/>
544  call assert_equal(['No mapping found'], execute('imap')->trim()->split("\n"))
545
546  " List global, buffer local and script local mappings
547  nmap ,f /^\k\+ (<CR>
548  nmap <buffer> ,f /^\k\+ (<CR>
549  nmap <script> ,fs /^\k\+ (<CR>
550  call assert_equal(['n  ,f           @/^\k\+ (<CR>',
551        \ 'n  ,fs         & /^\k\+ (<CR>',
552        \ 'n  ,f            /^\k\+ (<CR>'],
553        \ execute('nmap ,f')->trim()->split("\n"))
554
555  " List <Nop> mapping
556  nmap ,n <Nop>
557  call assert_equal(['n  ,n            <Nop>'],
558        \ execute('nmap ,n')->trim()->split("\n"))
559
560  " verbose map
561  call assert_match("\tLast set from .*/test_mapping.vim line \\d\\+$",
562        \ execute('verbose map ,n')->trim()->split("\n")[1])
563
564  " character with K_SPECIAL byte in rhs
565  nmap foo …
566  call assert_equal(['n  foo           …'],
567        \ execute('nmap foo')->trim()->split("\n"))
568
569  " modified character with K_SPECIAL byte in rhs
570  nmap foo <M-…>
571  call assert_equal(['n  foo           <M-…>'],
572        \ execute('nmap foo')->trim()->split("\n"))
573
574  " character with K_SPECIAL byte in lhs
575  nmap … foo
576  call assert_equal(['n  …             foo'],
577        \ execute('nmap …')->trim()->split("\n"))
578
579  " modified character with K_SPECIAL byte in lhs
580  nmap <M-…> foo
581  call assert_equal(['n  <M-…>         foo'],
582        \ execute('nmap <M-…>')->trim()->split("\n"))
583
584  " illegal bytes
585  let str = ":\x7f:\x80:\x90:\xd0:"
586  exe 'nmap foo ' .. str
587  call assert_equal(['n  foo           ' .. strtrans(str)],
588        \ execute('nmap foo')->trim()->split("\n"))
589  unlet str
590
591  " map to CTRL-V
592  exe "nmap ,k \<C-V>"
593  call assert_equal(['n  ,k            <Nop>'],
594        \ execute('nmap ,k')->trim()->split("\n"))
595
596  " map with space at the beginning
597  exe "nmap \<C-V> w <Nop>"
598  call assert_equal(['n  <Space>w      <Nop>'],
599        \ execute("nmap \<C-V> w")->trim()->split("\n"))
600
601  nmapclear
602endfunc
603
604func Test_expr_map_gets_cursor()
605  new
606  call setline(1, ['one', 'some w!rd'])
607  func StoreColumn()
608    let g:exprLine = line('.')
609    let g:exprCol = col('.')
610    return 'x'
611  endfunc
612  nnoremap <expr> x StoreColumn()
613  2
614  nmap ! f!<Ignore>x
615  call feedkeys("!", 'xt')
616  call assert_equal('some wrd', getline(2))
617  call assert_equal(2, g:exprLine)
618  call assert_equal(7, g:exprCol)
619
620  bwipe!
621  unlet g:exprLine
622  unlet g:exprCol
623  delfunc StoreColumn
624  nunmap x
625  nunmap !
626endfunc
627
628func Test_expr_map_restore_cursor()
629  CheckScreendump
630
631  let lines =<< trim END
632      call setline(1, ['one', 'two', 'three'])
633      2
634      set ls=2
635      hi! link StatusLine ErrorMsg
636      noremap <expr> <C-B> Func()
637      func Func()
638	  let g:on = !get(g:, 'on', 0)
639	  redraws
640	  return ''
641      endfunc
642      func Status()
643	  return get(g:, 'on', 0) ? '[on]' : ''
644      endfunc
645      set stl=%{Status()}
646  END
647  call writefile(lines, 'XtestExprMap')
648  let buf = RunVimInTerminal('-S XtestExprMap', #{rows: 10})
649  call term_sendkeys(buf, "\<C-B>")
650  call VerifyScreenDump(buf, 'Test_map_expr_1', {})
651
652  " clean up
653  call StopVimInTerminal(buf)
654  call delete('XtestExprMap')
655endfunc
656
657func Test_map_listing()
658  CheckScreendump
659
660  let lines =<< trim END
661      nmap a b
662  END
663  call writefile(lines, 'XtestMapList')
664  let buf = RunVimInTerminal('-S XtestMapList', #{rows: 6})
665  call term_sendkeys(buf, ":                      nmap a\<CR>")
666  call VerifyScreenDump(buf, 'Test_map_list_1', {})
667
668  " clean up
669  call StopVimInTerminal(buf)
670  call delete('XtestMapList')
671endfunc
672
673func Test_expr_map_error()
674  CheckScreendump
675
676  let lines =<< trim END
677      func Func()
678        throw 'test'
679        return ''
680      endfunc
681
682      nnoremap <expr> <F2> Func()
683      cnoremap <expr> <F2> Func()
684
685      call test_override('ui_delay', 10)
686  END
687  call writefile(lines, 'XtestExprMap')
688  let buf = RunVimInTerminal('-S XtestExprMap', #{rows: 10})
689  call term_sendkeys(buf, "\<F2>")
690  call TermWait(buf)
691  call term_sendkeys(buf, "\<CR>")
692  call VerifyScreenDump(buf, 'Test_map_expr_2', {})
693
694  call term_sendkeys(buf, ":abc\<F2>")
695  call VerifyScreenDump(buf, 'Test_map_expr_3', {})
696  call term_sendkeys(buf, "\<Esc>0")
697  call VerifyScreenDump(buf, 'Test_map_expr_4', {})
698
699  " clean up
700  call StopVimInTerminal(buf)
701  call delete('XtestExprMap')
702endfunc
703
704" Test for mapping errors
705func Test_map_error()
706  call assert_fails('unmap', 'E474:')
707  call assert_fails("exe 'map ' .. repeat('a', 51) .. ' :ls'", 'E474:')
708  call assert_fails('unmap abc', 'E31:')
709  call assert_fails('unabbr abc', 'E24:')
710  call assert_equal('', maparg(''))
711  call assert_fails('echo maparg("abc", [])', 'E730:')
712
713  " unique map
714  map ,w /[#&!]<CR>
715  call assert_fails("map <unique> ,w /[#&!]<CR>", 'E227:')
716  " unique buffer-local map
717  call assert_fails("map <buffer> <unique> ,w /[.,;]<CR>", 'E225:')
718  unmap ,w
719
720  " unique abbreviation
721  abbr SP special
722  call assert_fails("abbr <unique> SP special", 'E226:')
723  " unique buffer-local map
724  call assert_fails("abbr <buffer> <unique> SP special", 'E224:')
725  unabbr SP
726
727  call assert_fails('mapclear abc', 'E474:')
728  call assert_fails('abclear abc', 'E474:')
729  call assert_fails('abbr $xyz abc', 'E474:')
730
731  " space character in an abbreviation
732  call assert_fails('abbr ab<space> ABC', 'E474:')
733
734  " invalid <expr> map
735  map <expr> ,f abc
736  call assert_fails('normal ,f', 'E121:')
737  unmap <expr> ,f
738
739  " Recursive use of :normal in a map
740  set maxmapdepth=100
741  map gq :normal gq<CR>
742  call assert_fails('normal gq', 'E192:')
743  unmap gq
744  set maxmapdepth&
745endfunc
746
747" Test for <special> key mapping
748func Test_map_special()
749  throw 'skipped: Nvim does not support cpoptions flag "<"'
750  new
751  let old_cpo = &cpo
752  set cpo+=<
753  imap <F12> Blue
754  call feedkeys("i\<F12>", "x")
755  call assert_equal("<F12>", getline(1))
756  call feedkeys("ddi<F12>", "x")
757  call assert_equal("Blue", getline(1))
758  iunmap <F12>
759  imap <special> <F12> Green
760  call feedkeys("ddi\<F12>", "x")
761  call assert_equal("Green", getline(1))
762  call feedkeys("ddi<F12>", "x")
763  call assert_equal("<F12>", getline(1))
764  iunmap <special> <F12>
765  let &cpo = old_cpo
766  %bwipe!
767endfunc
768
769" Test for hasmapto()
770func Test_hasmapto()
771  call assert_equal(0, hasmapto('/^\k\+ ('))
772  map ,f /^\k\+ (<CR>
773  call assert_equal(1, hasmapto('/^\k\+ ('))
774  unmap ,f
775
776  " Insert mode mapping
777  call assert_equal(0, hasmapto('/^\k\+ (', 'i'))
778  imap ,f /^\k\+ (<CR>
779  call assert_equal(1, hasmapto('/^\k\+ (', 'i'))
780  iunmap ,f
781
782  " Normal mode mapping
783  call assert_equal(0, hasmapto('/^\k\+ (', 'n'))
784  nmap ,f /^\k\+ (<CR>
785  call assert_equal(1, hasmapto('/^\k\+ ('))
786  call assert_equal(1, hasmapto('/^\k\+ (', 'n'))
787  nunmap ,f
788
789  " Visual and Select mode mapping
790  call assert_equal(0, hasmapto('/^\k\+ (', 'v'))
791  call assert_equal(0, hasmapto('/^\k\+ (', 'x'))
792  call assert_equal(0, hasmapto('/^\k\+ (', 's'))
793  vmap ,f /^\k\+ (<CR>
794  call assert_equal(1, hasmapto('/^\k\+ (', 'v'))
795  call assert_equal(1, hasmapto('/^\k\+ (', 'x'))
796  call assert_equal(1, hasmapto('/^\k\+ (', 's'))
797  vunmap ,f
798
799  " Visual mode mapping
800  call assert_equal(0, hasmapto('/^\k\+ (', 'x'))
801  xmap ,f /^\k\+ (<CR>
802  call assert_equal(1, hasmapto('/^\k\+ (', 'v'))
803  call assert_equal(1, hasmapto('/^\k\+ (', 'x'))
804  call assert_equal(0, hasmapto('/^\k\+ (', 's'))
805  xunmap ,f
806
807  " Select mode mapping
808  call assert_equal(0, hasmapto('/^\k\+ (', 's'))
809  smap ,f /^\k\+ (<CR>
810  call assert_equal(1, hasmapto('/^\k\+ (', 'v'))
811  call assert_equal(0, hasmapto('/^\k\+ (', 'x'))
812  call assert_equal(1, hasmapto('/^\k\+ (', 's'))
813  sunmap ,f
814
815  " Operator-pending mode mapping
816  call assert_equal(0, hasmapto('/^\k\+ (', 'o'))
817  omap ,f /^\k\+ (<CR>
818  call assert_equal(1, hasmapto('/^\k\+ (', 'o'))
819  ounmap ,f
820
821  " Language mapping
822  call assert_equal(0, hasmapto('/^\k\+ (', 'l'))
823  lmap ,f /^\k\+ (<CR>
824  call assert_equal(1, hasmapto('/^\k\+ (', 'l'))
825  lunmap ,f
826
827  " Cmdline mode mapping
828  call assert_equal(0, hasmapto('/^\k\+ (', 'c'))
829  cmap ,f /^\k\+ (<CR>
830  call assert_equal(1, hasmapto('/^\k\+ (', 'c'))
831  cunmap ,f
832
833  call assert_equal(0, hasmapto('/^\k\+ (', 'n', 1))
834endfunc
835
836" Test for command-line completion of maps
837func Test_mapcomplete()
838  call assert_equal(['<buffer>', '<expr>', '<nowait>', '<script>',
839	      \ '<silent>', '<special>', '<unique>'],
840	      \ getcompletion('', 'mapping'))
841  call assert_equal([], getcompletion(',d', 'mapping'))
842
843  call feedkeys(":unmap <buf\<C-A>\<C-B>\"\<CR>", 'tx')
844  call assert_equal('"unmap <buffer>', @:)
845
846  call feedkeys(":unabbr <buf\<C-A>\<C-B>\"\<CR>", 'tx')
847  call assert_equal('"unabbr <buffer>', @:)
848
849  call feedkeys(":abbr! \<C-A>\<C-B>\"\<CR>", 'tx')
850  call assert_equal("\"abbr! \x01", @:)
851
852  " When multiple matches have the same {lhs}, it should only appear once.
853  " The simplified form should also not be included.
854  nmap ,<C-F> /H<CR>
855  omap ,<C-F> /H<CR>
856  call feedkeys(":map ,\<C-A>\<C-B>\"\<CR>", 'tx')
857  call assert_equal('"map ,<C-F>', @:)
858  mapclear
859endfunc
860
861func GetAbbrText()
862  unabbr hola
863  return 'hello'
864endfunc
865
866" Test for <expr> in abbreviation
867func Test_expr_abbr()
868  new
869  iabbr <expr> teh "the"
870  call feedkeys("iteh ", "tx")
871  call assert_equal('the ', getline(1))
872  iabclear
873  call setline(1, '')
874
875  " invalid <expr> abbreviation
876  abbr <expr> hte GetAbbr()
877  call assert_fails('normal ihte ', 'E117:')
878  call assert_equal('', getline(1))
879  unabbr <expr> hte
880
881  " evaluating the expression deletes the abbreviation
882  abbr <expr> hola GetAbbrText()
883  call assert_equal('GetAbbrText()', maparg('hola', 'i', '1'))
884  call feedkeys("ahola \<Esc>", 'xt')
885  call assert_equal('hello ', getline('.'))
886  call assert_equal('', maparg('hola', 'i', '1'))
887
888  bwipe!
889endfunc
890
891" Test for storing mappings in different modes in a vimrc file
892func Test_mkvimrc_mapmodes()
893  map a1 /a1
894  nmap a2 /a2
895  vmap a3 /a3
896  smap a4 /a4
897  xmap a5 /a5
898  omap a6 /a6
899  map! a7 /a7
900  imap a8 /a8
901  lmap a9 /a9
902  cmap a10 /a10
903  tmap a11 /a11
904  " Normal + Visual map
905  map a12 /a12
906  sunmap a12
907  ounmap a12
908  " Normal + Selectmode map
909  map a13 /a13
910  xunmap a13
911  ounmap a13
912  " Normal + OpPending map
913  map a14 /a14
914  vunmap a14
915  " Visual + Selectmode map
916  map a15 /a15
917  nunmap a15
918  ounmap a15
919  " Visual + OpPending map
920  map a16 /a16
921  nunmap a16
922  sunmap a16
923  " Selectmode + OpPending map
924  map a17 /a17
925  nunmap a17
926  xunmap a17
927  " Normal + Visual + Selectmode map
928  map a18 /a18
929  ounmap a18
930  " Normal + Visual + OpPending map
931  map a19 /a19
932  sunmap a19
933  " Normal + Selectmode + OpPending map
934  map a20 /a20
935  xunmap a20
936  " Visual + Selectmode + OpPending map
937  map a21 /a21
938  nunmap a21
939  " Mapping to Nop
940  map a22 <Nop>
941  " Script local mapping
942  map <script> a23 /a23
943
944  " Newline in {lhs} and {rhs} of a map
945  exe "map a24\<C-V>\<C-J> ia24\<C-V>\<C-J><Esc>"
946
947  " Abbreviation
948  abbr a25 A25
949  cabbr a26 A26
950  iabbr a27 A27
951
952  mkvimrc! Xvimrc
953  let l = readfile('Xvimrc')
954  call assert_equal(['map a1 /a1'], filter(copy(l), 'v:val =~ " a1 "'))
955  call assert_equal(['nmap a2 /a2'], filter(copy(l), 'v:val =~ " a2 "'))
956  call assert_equal(['vmap a3 /a3'], filter(copy(l), 'v:val =~ " a3 "'))
957  call assert_equal(['smap a4 /a4'], filter(copy(l), 'v:val =~ " a4 "'))
958  call assert_equal(['xmap a5 /a5'], filter(copy(l), 'v:val =~ " a5 "'))
959  call assert_equal(['omap a6 /a6'], filter(copy(l), 'v:val =~ " a6 "'))
960  call assert_equal(['map! a7 /a7'], filter(copy(l), 'v:val =~ " a7 "'))
961  call assert_equal(['imap a8 /a8'], filter(copy(l), 'v:val =~ " a8 "'))
962  call assert_equal(['lmap a9 /a9'], filter(copy(l), 'v:val =~ " a9 "'))
963  call assert_equal(['cmap a10 /a10'], filter(copy(l), 'v:val =~ " a10 "'))
964  call assert_equal(['tmap a11 /a11'], filter(copy(l), 'v:val =~ " a11 "'))
965  call assert_equal(['nmap a12 /a12', 'xmap a12 /a12'],
966        \ filter(copy(l), 'v:val =~ " a12 "'))
967  call assert_equal(['nmap a13 /a13', 'smap a13 /a13'],
968        \ filter(copy(l), 'v:val =~ " a13 "'))
969  call assert_equal(['nmap a14 /a14', 'omap a14 /a14'],
970        \ filter(copy(l), 'v:val =~ " a14 "'))
971  call assert_equal(['vmap a15 /a15'], filter(copy(l), 'v:val =~ " a15 "'))
972  call assert_equal(['xmap a16 /a16', 'omap a16 /a16'],
973        \ filter(copy(l), 'v:val =~ " a16 "'))
974  call assert_equal(['smap a17 /a17', 'omap a17 /a17'],
975        \ filter(copy(l), 'v:val =~ " a17 "'))
976  call assert_equal(['nmap a18 /a18', 'vmap a18 /a18'],
977        \ filter(copy(l), 'v:val =~ " a18 "'))
978  call assert_equal(['nmap a19 /a19', 'xmap a19 /a19', 'omap a19 /a19'],
979        \ filter(copy(l), 'v:val =~ " a19 "'))
980  call assert_equal(['nmap a20 /a20', 'smap a20 /a20', 'omap a20 /a20'],
981        \ filter(copy(l), 'v:val =~ " a20 "'))
982  call assert_equal(['vmap a21 /a21', 'omap a21 /a21'],
983        \ filter(copy(l), 'v:val =~ " a21 "'))
984  call assert_equal(['map a22 <Nop>'], filter(copy(l), 'v:val =~ " a22 "'))
985  call assert_equal([], filter(copy(l), 'v:val =~ " a23 "'))
986  call assert_equal(["map a24<NL> ia24<NL>\x16\e"],
987        \ filter(copy(l), 'v:val =~ " a24"'))
988
989  call assert_equal(['abbr a25 A25'], filter(copy(l), 'v:val =~ " a25 "'))
990  call assert_equal(['cabbr a26 A26'], filter(copy(l), 'v:val =~ " a26 "'))
991  call assert_equal(['iabbr a27 A27'], filter(copy(l), 'v:val =~ " a27 "'))
992  call delete('Xvimrc')
993
994  mapclear
995  nmapclear
996  vmapclear
997  xmapclear
998  smapclear
999  omapclear
1000  imapclear
1001  lmapclear
1002  cmapclear
1003  tmapclear
1004endfunc
1005
1006" Test for recursive mapping ('maxmapdepth')
1007func Test_map_recursive()
1008  map x y
1009  map y x
1010  call assert_fails('normal x', 'E223:')
1011  unmap x
1012  unmap y
1013endfunc
1014
1015" Test for removing an abbreviation using {rhs} and with space after {lhs}
1016func Test_abbr_remove()
1017  abbr foo bar
1018  let d = maparg('foo', 'i', 1, 1)
1019  call assert_equal(['foo', 'bar', '!'], [d.lhs, d.rhs, d.mode])
1020  unabbr bar
1021  call assert_equal({}, maparg('foo', 'i', 1, 1))
1022
1023  abbr foo bar
1024  unabbr foo<space><tab>
1025  call assert_equal({}, maparg('foo', 'i', 1, 1))
1026endfunc
1027
1028" Trigger an abbreviation using a special key
1029func Test_abbr_trigger_special()
1030  new
1031  iabbr teh the
1032  call feedkeys("iteh\<F2>\<Esc>", 'xt')
1033  call assert_equal('the<F2>', getline(1))
1034  iunab teh
1035  close!
1036endfunc
1037
1038" Test for '<' in 'cpoptions'
1039func Test_map_cpo_special_keycode()
1040  set cpo-=<
1041  imap x<Bslash>k Test
1042  let d = maparg('x<Bslash>k', 'i', 0, 1)
1043  call assert_equal(['x\k', 'Test', 'i'], [d.lhs, d.rhs, d.mode])
1044  call feedkeys(":imap x\<C-A>\<C-B>\"\<CR>", 'tx')
1045  call assert_equal('"imap x\k', @:)
1046  iunmap x<Bslash>k
1047  " Nvim: no "<" flag in 'cpoptions'.
1048  " set cpo+=<
1049  " imap x<Bslash>k Test
1050  " let d = maparg('x<Bslash>k', 'i', 0, 1)
1051  " call assert_equal(['x<Bslash>k', 'Test', 'i'], [d.lhs, d.rhs, d.mode])
1052  " call feedkeys(":imap x\<C-A>\<C-B>\"\<CR>", 'tx')
1053  " call assert_equal('"imap x<Bslash>k', @:)
1054  " iunmap x<Bslash>k
1055  set cpo-=<
1056  " Modifying 'cpo' above adds some default mappings, remove them
1057  mapclear
1058  mapclear!
1059endfunc
1060
1061" Test for <Cmd> key in maps to execute commands
1062func Test_map_cmdkey()
1063  new
1064
1065  " Error cases
1066  let x = 0
1067  noremap <F3> <Cmd><Cmd>let x = 1<CR>
1068  call assert_fails('call feedkeys("\<F3>", "xt")', 'E1136:')
1069  call assert_equal(0, x)
1070
1071  noremap <F3> <Cmd>let x = 3
1072  call assert_fails('call feedkeys("\<F3>", "xt!")', 'E1255:')
1073  call assert_equal(0, x)
1074
1075  " works in various modes and sees the correct mode()
1076  noremap <F3> <Cmd>let m = mode(1)<CR>
1077  noremap! <F3> <Cmd>let m = mode(1)<CR>
1078
1079  " normal mode
1080  call feedkeys("\<F3>", 'xt')
1081  call assert_equal('n', m)
1082
1083  " visual mode
1084  call feedkeys("v\<F3>", 'xt!')
1085  call assert_equal('v', m)
1086  " shouldn't leave the visual mode
1087  call assert_equal('v', mode(1))
1088  call feedkeys("\<Esc>", 'xt')
1089  call assert_equal('n', mode(1))
1090
1091  " visual mapping in select mode
1092  call feedkeys("gh\<F3>", 'xt!')
1093  call assert_equal('v', m)
1094  " shouldn't leave select mode
1095  call assert_equal('s', mode(1))
1096  call feedkeys("\<Esc>", 'xt')
1097  call assert_equal('n', mode(1))
1098
1099  " select mode mapping
1100  snoremap <F3> <Cmd>let m = mode(1)<cr>
1101  call feedkeys("gh\<F3>", 'xt!')
1102  call assert_equal('s', m)
1103  " shouldn't leave select mode
1104  call assert_equal('s', mode(1))
1105  call feedkeys("\<Esc>", 'xt')
1106  call assert_equal('n', mode(1))
1107
1108  " operator-pending mode
1109  call feedkeys("d\<F3>", 'xt!')
1110  call assert_equal('no', m)
1111  " leaves the operator-pending mode
1112  call assert_equal('n', mode(1))
1113
1114  " insert mode
1115  call feedkeys("i\<F3>abc", 'xt')
1116  call assert_equal('i', m)
1117  call assert_equal('abc', getline('.'))
1118
1119  " replace mode
1120  call feedkeys("0R\<F3>two", 'xt')
1121  call assert_equal('R', m)
1122  call assert_equal('two', getline('.'))
1123
1124  " virtual replace mode
1125  call setline('.', "one\ttwo")
1126  call feedkeys("4|gR\<F3>xxx", 'xt')
1127  call assert_equal('Rv', m)
1128  call assert_equal("onexxx\ttwo", getline('.'))
1129
1130  " cmdline mode
1131  call feedkeys(":\<F3>\"xxx\<CR>", 'xt!')
1132  call assert_equal('c', m)
1133  call assert_equal('"xxx', @:)
1134
1135  " terminal mode
1136  if CanRunVimInTerminal()
1137    tnoremap <F3> <Cmd>let m = mode(1)<CR>
1138    let buf = Run_shell_in_terminal({})
1139    call feedkeys("\<F3>", 'xt')
1140    call assert_equal('t', m)
1141    call assert_equal('t', mode(1))
1142    call StopShellInTerminal(buf)
1143    close!
1144    tunmap <F3>
1145  endif
1146
1147  " invoke cmdline mode recursively
1148  noremap! <F2> <Cmd>norm! :foo<CR>
1149  %d
1150  call setline(1, ['some short lines', 'of test text'])
1151  call feedkeys(":bar\<F2>x\<C-B>\"\r", 'xt')
1152  call assert_equal('"barx', @:)
1153
1154  " test for chars with 0x80 or 0x9b bytes
1155  map <F2> <Cmd>let x = '洛固四最倒倀'<CR>
1156  call feedkeys("\<F2>", 'xt')
1157  call assert_equal('洛固四最倒倀', x)
1158
1159  " test for calling a <SID> function
1160  let lines =<< trim END
1161    map <F2> <Cmd>call <SID>do_it()<CR>
1162    func s:do_it()
1163      let g:x = 32
1164    endfunc
1165  END
1166  call writefile(lines, 'Xscript', 'D')
1167  source Xscript
1168  call feedkeys("\<F2>", 'xt')
1169  call assert_equal(32, g:x)
1170  unlet g:x
1171
1172  unmap <F2>
1173  unmap! <F2>
1174  unmap <F3>
1175  unmap! <F3>
1176  %bw!
1177endfunc
1178
1179" text object enters visual mode
1180func TextObj()
1181  if mode() !=# "v"
1182    normal! v
1183  end
1184  call cursor(1, 3)
1185  normal! o
1186  call cursor(2, 4)
1187endfunc
1188
1189func s:cmdmap(lhs, rhs)
1190  exe 'noremap ' .. a:lhs .. ' <Cmd>' .. a:rhs .. '<CR>'
1191  exe 'noremap! ' .. a:lhs .. ' <Cmd>' .. a:rhs .. '<CR>'
1192endfunc
1193
1194func s:cmdunmap(lhs)
1195  exe 'unmap ' .. a:lhs
1196  exe 'unmap! ' .. a:lhs
1197endfunc
1198
1199" Map various <Fx> keys used by the <Cmd> key tests
1200func s:setupMaps()
1201  call s:cmdmap('<F3>', 'let m = mode(1)')
1202  call s:cmdmap('<F4>', 'normal! ww')
1203  call s:cmdmap('<F5>', 'normal! "ay')
1204  call s:cmdmap('<F6>', 'throw "very error"')
1205  call s:cmdmap('<F7>', 'call TextObj()')
1206  call s:cmdmap('<F8>', 'startinsert')
1207  call s:cmdmap('<F9>', 'stopinsert')
1208endfunc
1209
1210" Remove the mappings setup by setupMaps()
1211func s:cleanupMaps()
1212  call s:cmdunmap('<F3>')
1213  call s:cmdunmap('<F4>')
1214  call s:cmdunmap('<F5>')
1215  call s:cmdunmap('<F6>')
1216  call s:cmdunmap('<F7>')
1217  call s:cmdunmap('<F8>')
1218  call s:cmdunmap('<F9>')
1219endfunc
1220
1221" Test for <Cmd> mapping in normal mode
1222func Test_map_cmdkey_normal_mode()
1223  new
1224  call s:setupMaps()
1225
1226  " check v:count and v:register works
1227  call s:cmdmap('<F2>', 'let s = [mode(1), v:count, v:register]')
1228  call feedkeys("\<F2>", 'xt')
1229  call assert_equal(['n', 0, '"'], s)
1230  call feedkeys("7\<F2>", 'xt')
1231  call assert_equal(['n', 7, '"'], s)
1232  call feedkeys("\"e\<F2>", 'xt')
1233  call assert_equal(['n', 0, 'e'], s)
1234  call feedkeys("5\"k\<F2>", 'xt')
1235  call assert_equal(['n', 5, 'k'], s)
1236  call s:cmdunmap('<F2>')
1237
1238  call setline(1, ['some short lines', 'of test text'])
1239  call feedkeys("\<F7>y", 'xt')
1240  call assert_equal("me short lines\nof t", @")
1241  call assert_equal('v', getregtype('"'))
1242  call assert_equal([0, 1, 3, 0], getpos("'<"))
1243  call assert_equal([0, 2, 4, 0], getpos("'>"))
1244
1245  " startinsert
1246  %d
1247  call feedkeys("\<F8>abc", 'xt')
1248  call assert_equal('abc', getline(1))
1249
1250  " feedkeys are not executed immediately
1251  noremap ,a <Cmd>call feedkeys("aalpha") \| let g:a = getline(2)<CR>
1252  %d
1253  call setline(1, ['some short lines', 'of test text'])
1254  call cursor(2, 3)
1255  call feedkeys(",a\<F3>", 'xt')
1256  call assert_equal('of test text', g:a)
1257  call assert_equal('n', m)
1258  call assert_equal(['some short lines', 'of alphatest text'], getline(1, '$'))
1259  nunmap ,a
1260
1261  " feedkeys(..., 'x') is executed immediately, but insert mode is aborted
1262  noremap ,b <Cmd>call feedkeys("abeta", 'x') \| let g:b = getline(2)<CR>
1263  call feedkeys(",b\<F3>", 'xt')
1264  call assert_equal('n', m)
1265  call assert_equal('of alphabetatest text', g:b)
1266  nunmap ,b
1267
1268  call s:cleanupMaps()
1269  %bw!
1270endfunc
1271
1272" Test for <Cmd> mapping with the :normal command
1273func Test_map_cmdkey_normal_cmd()
1274  new
1275  noremap ,x <Cmd>call append(1, "xx") \| call append(1, "aa")<CR>
1276  noremap ,f <Cmd>nosuchcommand<CR>
1277  noremap ,e <Cmd>throw "very error" \| call append(1, "yy")<CR>
1278  noremap ,m <Cmd>echoerr "The message." \| call append(1, "zz")<CR>
1279  noremap ,w <Cmd>for i in range(5) \| if i==1 \| echoerr "Err" \| endif \| call append(1, i) \| endfor<CR>
1280
1281  call setline(1, ['some short lines', 'of test text'])
1282  exe "norm ,x\r"
1283  call assert_equal(['some short lines', 'aa', 'xx', 'of test text'], getline(1, '$'))
1284
1285  call assert_fails('norm ,f', 'E492:')
1286  call assert_fails('norm ,e', 'very error')
1287  call assert_fails('norm ,m', 'The message.')
1288  call assert_equal(['some short lines', 'aa', 'xx', 'of test text'], getline(1, '$'))
1289
1290  %d
1291  let caught_err = 0
1292  try
1293    exe "normal ,w"
1294  catch /Vim(echoerr):Err/
1295    let caught_err = 1
1296  endtry
1297  call assert_equal(1, caught_err)
1298  call assert_equal(['', '0'], getline(1, '$'))
1299
1300  %d
1301  call assert_fails('normal ,w', 'Err')
1302  call assert_equal(['', '4', '3', '2' ,'1', '0'], getline(1, '$'))
1303  call assert_equal(1, line('.'))
1304
1305  nunmap ,x
1306  nunmap ,f
1307  nunmap ,e
1308  nunmap ,m
1309  nunmap ,w
1310  %bw!
1311endfunc
1312
1313" Test for <Cmd> mapping in visual mode
1314func Test_map_cmdkey_visual_mode()
1315  new
1316  set showmode
1317  call s:setupMaps()
1318
1319  call setline(1, ['some short lines', 'of test text'])
1320  call feedkeys("v\<F4>", 'xt!')
1321  call assert_equal(['v', 1, 12], [mode(1), col('v'), col('.')])
1322
1323  " can invoke an operator, ending the visual mode
1324  let @a = ''
1325  call feedkeys("\<F5>", 'xt!')
1326  call assert_equal('n', mode(1))
1327  call assert_equal('some short l', @a)
1328
1329  " error doesn't interrupt visual mode
1330  call assert_fails('call feedkeys("ggvw\<F6>", "xt!")', 'E605:')
1331  call assert_equal(['v', 1, 6], [mode(1), col('v'), col('.')])
1332  call feedkeys("\<F7>", 'xt!')
1333  call assert_equal(['v', 1, 3, 2, 4], [mode(1), line('v'), col('v'), line('.'), col('.')])
1334
1335  " startinsert gives "-- (insert) VISUAL --" mode
1336  call feedkeys("\<F8>", 'xt!')
1337  call assert_equal(['v', 1, 3, 2, 4], [mode(1), line('v'), col('v'), line('.'), col('.')])
1338  redraw!
1339  call assert_match('^-- (insert) VISUAL --', Screenline(&lines))
1340  call feedkeys("\<Esc>new ", 'x')
1341  call assert_equal(['some short lines', 'of new test text'], getline(1, '$'))
1342
1343  call s:cleanupMaps()
1344  set showmode&
1345  %bw!
1346endfunc
1347
1348" Test for <Cmd> mapping in select mode
1349func Test_map_cmdkey_select_mode()
1350  new
1351  set showmode
1352  call s:setupMaps()
1353
1354  snoremap <F1> <cmd>throw "very error"<CR>
1355  snoremap <F2> <cmd>normal! <c-g>"by<CR>
1356  call setline(1, ['some short lines', 'of test text'])
1357
1358  call feedkeys("gh\<F4>", "xt!")
1359  call assert_equal(['s', 1, 12], [mode(1), col('v'), col('.')])
1360  redraw!
1361  call assert_match('^-- SELECT --', Screenline(&lines))
1362
1363  " visual mapping in select mode restarts select mode after operator
1364  let @a = ''
1365  call feedkeys("\<F5>", 'xt!')
1366  call assert_equal('s', mode(1))
1367  call assert_equal('some short l', @a)
1368
1369  " select mode mapping works, and does not restart select mode
1370  let @b = ''
1371  call feedkeys("\<F2>", 'xt!')
1372  call assert_equal('n', mode(1))
1373  call assert_equal('some short l', @b)
1374
1375  " error doesn't interrupt temporary visual mode
1376  call assert_fails('call feedkeys("\<Esc>ggvw\<C-G>\<F6>", "xt!")', 'E605:')
1377  redraw!
1378  call assert_match('^-- VISUAL --', Screenline(&lines))
1379  " quirk: restoration of select mode is not performed
1380  call assert_equal(['v', 1, 6], [mode(1), col('v'), col('.')])
1381
1382  " error doesn't interrupt select mode
1383  call assert_fails('call feedkeys("\<Esc>ggvw\<C-G>\<F1>", "xt!")', 'E605:')
1384  redraw!
1385  call assert_match('^-- SELECT --', Screenline(&lines))
1386  call assert_equal(['s', 1, 6], [mode(1), col('v'), col('.')])
1387
1388  call feedkeys("\<F7>", 'xt!')
1389  redraw!
1390  call assert_match('^-- SELECT --', Screenline(&lines))
1391  call assert_equal(['s', 1, 3, 2, 4], [mode(1), line('v'), col('v'), line('.'), col('.')])
1392
1393  " startinsert gives "-- SELECT (insert) --" mode
1394  call feedkeys("\<F8>", 'xt!')
1395  redraw!
1396  call assert_match('^-- (insert) SELECT --', Screenline(&lines))
1397  call assert_equal(['s', 1, 3, 2, 4], [mode(1), line('v'), col('v'), line('.'), col('.')])
1398  call feedkeys("\<Esc>new ", 'x')
1399  call assert_equal(['some short lines', 'of new test text'], getline(1, '$'))
1400
1401  sunmap <F1>
1402  sunmap <F2>
1403  call s:cleanupMaps()
1404  set showmode&
1405  %bw!
1406endfunc
1407
1408" Test for <Cmd> mapping in operator-pending mode
1409func Test_map_cmdkey_op_pending_mode()
1410  new
1411  call s:setupMaps()
1412
1413  call setline(1, ['some short lines', 'of test text'])
1414  call feedkeys("d\<F4>", 'xt')
1415  call assert_equal(['lines', 'of test text'], getline(1, '$'))
1416  call assert_equal(['some short '], getreg('"', 1, 1))
1417  " create a new undo point
1418  let &g:undolevels = &g:undolevels
1419
1420  call feedkeys(".", 'xt')
1421  call assert_equal(['test text'], getline(1, '$'))
1422  call assert_equal(['lines', 'of '], getreg('"', 1, 1))
1423  " create a new undo point
1424  let &g:undolevels = &g:undolevels
1425
1426  call feedkeys("uu", 'xt')
1427  call assert_equal(['some short lines', 'of test text'], getline(1, '$'))
1428
1429  " error aborts operator-pending, operator not performed
1430  call assert_fails('call feedkeys("d\<F6>", "xt")', 'E605:')
1431  call assert_equal(['some short lines', 'of test text'], getline(1, '$'))
1432
1433  call feedkeys("\"bd\<F7>", 'xt')
1434  call assert_equal(['soest text'], getline(1, '$'))
1435  call assert_equal(['me short lines', 'of t'], getreg('b', 1, 1))
1436
1437  " startinsert aborts operator
1438  call feedkeys("d\<F8>cc", 'xt')
1439  call assert_equal(['soccest text'], getline(1, '$'))
1440
1441  call s:cleanupMaps()
1442  %bw!
1443endfunc
1444
1445" Test for <Cmd> mapping in insert mode
1446func Test_map_cmdkey_insert_mode()
1447  new
1448  call s:setupMaps()
1449
1450  call setline(1, ['some short lines', 'of test text'])
1451  " works the same as <C-O>w<C-O>w
1452  call feedkeys("iindeed \<F4>little ", 'xt')
1453  call assert_equal(['indeed some short little lines', 'of test text'], getline(1, '$'))
1454  call assert_fails('call feedkeys("i\<F6> 2", "xt")', 'E605:')
1455  call assert_equal(['indeed some short little 2 lines', 'of test text'], getline(1, '$'))
1456
1457  " Note when entering visual mode from InsertEnter autocmd, an async event,
1458  " or a <Cmd> mapping, vim ends up in undocumented "INSERT VISUAL" mode.
1459  call feedkeys("i\<F7>stuff ", 'xt')
1460  call assert_equal(['indeed some short little 2 lines', 'of stuff test text'], getline(1, '$'))
1461  call assert_equal(['v', 1, 3, 2, 9], [mode(1), line('v'), col('v'), line('.'), col('.')])
1462
1463  call feedkeys("\<F5>", 'xt')
1464  call assert_equal(['deed some short little 2 lines', 'of stuff '], getreg('a', 1, 1))
1465
1466  " also works as part of abbreviation
1467  abbr foo <Cmd>let g:y = 17<CR>bar
1468  exe "normal i\<space>foo "
1469  call assert_equal(17, g:y)
1470  call assert_equal('in bar deed some short little 2 lines', getline(1))
1471  unabbr foo
1472
1473  " :startinsert does nothing
1474  call setline(1, 'foo bar')
1475  call feedkeys("ggi\<F8>vim", 'xt')
1476  call assert_equal('vimfoo bar', getline(1))
1477
1478  " :stopinsert works
1479  call feedkeys("ggi\<F9>Abc", 'xt')
1480  call assert_equal('vimfoo barbc', getline(1))
1481
1482  call s:cleanupMaps()
1483  %bw!
1484endfunc
1485
1486" Test for <Cmd> mapping in insert-completion mode
1487func Test_map_cmdkey_insert_complete_mode()
1488  new
1489  call s:setupMaps()
1490
1491  call setline(1, 'some short lines')
1492  call feedkeys("os\<C-X>\<C-N>\<F3>\<C-N> ", 'xt')
1493  call assert_equal('ic', m)
1494  call assert_equal(['some short lines', 'short '], getline(1, '$'))
1495
1496  call s:cleanupMaps()
1497  %bw!
1498endfunc
1499
1500" Test for <Cmd> mapping in cmdline mode
1501func Test_map_cmdkey_cmdline_mode()
1502  new
1503  call s:setupMaps()
1504
1505  call setline(1, ['some short lines', 'of test text'])
1506  let x = 0
1507  call feedkeys(":let x\<F3>= 10\r", 'xt')
1508  call assert_equal('c', m)
1509  call assert_equal(10, x)
1510
1511  " exception doesn't leave cmdline mode
1512  call assert_fails('call feedkeys(":let x\<F6>= 20\r", "xt")', 'E605:')
1513  call assert_equal(20, x)
1514
1515  " move cursor in the buffer from cmdline mode
1516  call feedkeys(":let x\<F4>= 30\r", 'xt')
1517  call assert_equal(30, x)
1518  call assert_equal(12, col('.'))
1519
1520  " :startinsert takes effect after leaving cmdline mode
1521  call feedkeys(":let x\<F8>= 40\rnew ", 'xt')
1522  call assert_equal(40, x)
1523  call assert_equal('some short new lines', getline(1))
1524
1525  call s:cleanupMaps()
1526  %bw!
1527endfunc
1528
1529func Test_map_cmdkey_redo()
1530  func SelectDash()
1531    call search('^---\n\zs', 'bcW')
1532    norm! V
1533    call search('\n\ze---$', 'W')
1534  endfunc
1535
1536  let text =<< trim END
1537      ---
1538      aaa
1539      ---
1540      bbb
1541      bbb
1542      ---
1543      ccc
1544      ccc
1545      ccc
1546      ---
1547  END
1548  new Xcmdtext
1549  call setline(1, text)
1550
1551  onoremap <silent> i- <Cmd>call SelectDash()<CR>
1552  call feedkeys('2Gdi-', 'xt')
1553  call assert_equal(['---', '---'], getline(1, 2))
1554  call feedkeys('j.', 'xt')
1555  call assert_equal(['---', '---', '---'], getline(1, 3))
1556  call feedkeys('j.', 'xt')
1557  call assert_equal(['---', '---', '---', '---'], getline(1, 4))
1558
1559  bwipe!
1560  call delete('Xcmdtext')
1561  delfunc SelectDash
1562  ounmap i-
1563
1564  new
1565  call setline(1, 'aaa bbb ccc ddd')
1566
1567  " command can contain special keys
1568  onoremap ix <Cmd>let g:foo ..= '…'<Bar>normal! <C-Right><CR>
1569  let g:foo = ''
1570  call feedkeys('0dix.', 'xt')
1571  call assert_equal('……', g:foo)
1572  call assert_equal('ccc ddd', getline(1))
1573  unlet g:foo
1574
1575  " command line ending in "0" is handled without errors
1576  onoremap ix <Cmd>eval 0<CR>
1577  call feedkeys('dix.', 'xt')
1578
1579  ounmap ix
1580  bwipe!
1581endfunc
1582
1583" Test for using <script> with a map to remap characters in rhs
1584func Test_script_local_remap()
1585  new
1586  inoremap <buffer> <SID>xyz mno
1587  inoremap <buffer> <script> abc st<SID>xyzre
1588  normal iabc
1589  call assert_equal('stmnore', getline(1))
1590  bwipe!
1591endfunc
1592
1593func Test_abbreviate_multi_byte()
1594  new
1595  iabbrev foo bar
1596  call feedkeys("ifoo…\<Esc>", 'xt')
1597  call assert_equal("bar…", getline(1))
1598  iunabbrev foo
1599  bwipe!
1600endfunc
1601
1602" Test for abbreviations with 'latin1' encoding
1603func Test_abbreviate_latin1_encoding()
1604  " set encoding=latin1
1605  call assert_fails('abbr ab#$c ABC', 'E474:')
1606  new
1607  iabbr <buffer> #i #include
1608  iabbr <buffer> ## #enddef
1609  exe "normal i#i\<C-]>"
1610  call assert_equal('#include', getline(1))
1611  exe "normal 0Di##\<C-]>"
1612  call assert_equal('#enddef', getline(1))
1613  %bw!
1614  set encoding=utf-8
1615endfunc
1616+
1617" Test for <Plug> always being mapped, even when used with "noremap".
1618func Test_plug_remap()
1619  let g:foo = 0
1620  nnoremap <Plug>(Increase_x) <Cmd>let g:foo += 1<CR>
1621  nmap <F2> <Plug>(Increase_x)
1622  nnoremap <F3> <Plug>(Increase_x)
1623  call feedkeys("\<F2>", 'xt')
1624  call assert_equal(1, g:foo)
1625  call feedkeys("\<F3>", 'xt')
1626  call assert_equal(2, g:foo)
1627  nnoremap x <Nop>
1628  nmap <F4> x<Plug>(Increase_x)x
1629  nnoremap <F5> x<Plug>(Increase_x)x
1630  call setline(1, 'Some text')
1631  normal! gg$
1632  call feedkeys("\<F4>", 'xt')
1633  call assert_equal(3, g:foo)
1634  call assert_equal('Some text', getline(1))
1635  call feedkeys("\<F5>", 'xt')
1636  call assert_equal(4, g:foo)
1637  call assert_equal('Some te', getline(1))
1638  nunmap <Plug>(Increase_x)
1639  nunmap <F2>
1640  nunmap <F3>
1641  nunmap <F4>
1642  nunmap <F5>
1643  unlet g:foo
1644  %bw!
1645endfunc
1646
1647func Test_mouse_drag_mapped_start_select()
1648  set mouse=a
1649  set selectmode=key,mouse
1650  func ClickExpr()
1651    call Ntest_setmouse(1, 1)
1652    return "\<LeftMouse>"
1653  endfunc
1654  func DragExpr()
1655    call Ntest_setmouse(1, 2)
1656    return "\<LeftDrag>"
1657  endfunc
1658  nnoremap <expr> <F2> ClickExpr()
1659  nmap <expr> <F3> DragExpr()
1660
1661  nnoremap <LeftDrag> <LeftDrag><Cmd><CR>
1662  exe "normal \<F2>\<F3>"
1663  call assert_equal('s', mode())
1664  exe "normal! \<C-\>\<C-N>"
1665
1666  nunmap <LeftDrag>
1667  nunmap <F2>
1668  nunmap <F3>
1669  delfunc ClickExpr
1670  delfunc DragExpr
1671  set selectmode&
1672  set mouse&
1673endfunc
1674
1675func Test_mouse_drag_statusline()
1676  set laststatus=2
1677  set mouse=a
1678  func ClickExpr()
1679    call Ntest_setmouse(&lines - 1, 1)
1680    return "\<LeftMouse>"
1681  endfunc
1682  func DragExpr()
1683    call Ntest_setmouse(&lines - 2, 1)
1684    return "\<LeftDrag>"
1685  endfunc
1686  nnoremap <expr> <F2> ClickExpr()
1687  nnoremap <expr> <F3> DragExpr()
1688
1689  " this was causing a crash in win_drag_status_line()
1690  call feedkeys("\<F2>:tabnew\<CR>\<F3>", 'tx')
1691
1692  nunmap <F2>
1693  nunmap <F3>
1694  delfunc ClickExpr
1695  delfunc DragExpr
1696  set laststatus& mouse&
1697endfunc
1698
1699" Test for mapping <LeftDrag> in Insert mode
1700func Test_mouse_drag_insert_map()
1701  set mouse=a
1702  func ClickExpr()
1703    call Ntest_setmouse(1, 1)
1704    return "\<LeftMouse>"
1705  endfunc
1706  func DragExpr()
1707    call Ntest_setmouse(1, 2)
1708    return "\<LeftDrag>"
1709  endfunc
1710  inoremap <expr> <F2> ClickExpr()
1711  imap <expr> <F3> DragExpr()
1712
1713  inoremap <LeftDrag> <LeftDrag><Cmd>let g:dragged = 1<CR>
1714  exe "normal i\<F2>\<F3>"
1715  call assert_equal(1, g:dragged)
1716  call assert_equal('v', mode())
1717  exe "normal! \<C-\>\<C-N>"
1718  unlet g:dragged
1719
1720  inoremap <LeftDrag> <LeftDrag><C-\><C-N>
1721  exe "normal i\<F2>\<F3>"
1722  call assert_equal('n', mode())
1723
1724  iunmap <LeftDrag>
1725  iunmap <F2>
1726  iunmap <F3>
1727  delfunc ClickExpr
1728  delfunc DragExpr
1729  set mouse&
1730endfunc
1731
1732func Test_unmap_simplifiable()
1733  map <C-I> foo
1734  map <Tab> bar
1735  call assert_equal('foo', maparg('<C-I>'))
1736  call assert_equal('bar', maparg('<Tab>'))
1737  unmap <C-I>
1738  call assert_equal('', maparg('<C-I>'))
1739  call assert_equal('bar', maparg('<Tab>'))
1740  unmap <Tab>
1741
1742  map <C-I> foo
1743  unmap <Tab>
1744  " This should not error
1745  unmap <C-I>
1746endfunc
1747
1748" Test that the first byte of rhs is not remapped if rhs starts with lhs.
1749func Test_map_rhs_starts_with_lhs()
1750  new
1751  func MapExpr()
1752    return "\<C-R>\<C-P>"
1753  endfunc
1754
1755  for expr in [v:false, v:true]
1756    if expr
1757      imap <buffer><expr> <C-R> MapExpr()
1758    else
1759      imap <buffer> <C-R> <C-R><C-P>
1760    endif
1761
1762    for restore in [v:false, v:true]
1763      if restore
1764        let saved = maparg('<C-R>', 'i', v:false, v:true)
1765        iunmap <buffer> <C-R>
1766        call mapset(saved)
1767      endif
1768
1769      let @a = 'foo'
1770      call assert_nobeep('call feedkeys("S\<C-R>a", "tx")')
1771      call assert_equal('foo', getline('.'))
1772
1773      let @a = 'bar'
1774      call assert_nobeep('call feedkeys("S\<*C-R>a", "tx")')
1775      call assert_equal('bar', getline('.'))
1776    endfor
1777  endfor
1778
1779  " When two mappings are used for <C-I> and <Tab>, remapping should work.
1780  imap <buffer> <C-I> <Tab>bar
1781  imap <buffer> <Tab> foo
1782  call feedkeys("S\<Tab>", 'xt')
1783  call assert_equal('foo', getline('.'))
1784  call feedkeys("S\<*C-I>", 'xt')
1785  call assert_equal('foobar', getline('.'))
1786
1787  delfunc MapExpr
1788  bwipe!
1789endfunc
1790
1791func Test_expr_map_escape_special()
1792  nnoremap … <Cmd>let g:got_ellipsis += 1<CR>
1793  func Func()
1794    return '…'
1795  endfunc
1796  nmap <expr> <F2> Func()
1797  let g:got_ellipsis = 0
1798  call feedkeys("\<F2>", 'xt')
1799  call assert_equal(1, g:got_ellipsis)
1800  delfunc Func
1801  nunmap <F2>
1802  unlet g:got_ellipsis
1803  nunmap …
1804endfunc
1805
1806" Testing for mapping after an <Nop> mapping is triggered on timeout.
1807" Test for what patch 8.1.0052 fixes.
1808func Test_map_after_timed_out_nop()
1809  CheckRunVimInTerminal
1810
1811  let lines =<< trim END
1812    set timeout timeoutlen=400
1813    inoremap ab TEST
1814    inoremap a <Nop>
1815  END
1816  call writefile(lines, 'Xtest_map_after_timed_out_nop', 'D')
1817  let buf = RunVimInTerminal('-S Xtest_map_after_timed_out_nop', #{rows: 6})
1818
1819  " Enter Insert mode
1820  call term_sendkeys(buf, 'i')
1821  " Wait for the "a" mapping to timeout
1822  call term_sendkeys(buf, 'a')
1823  call term_wait(buf, 500)
1824  " Send "a" and wait for a period shorter than 'timeoutlen'
1825  call term_sendkeys(buf, 'a')
1826  call term_wait(buf, 100)
1827  " Send "b", should trigger the "ab" mapping
1828  call term_sendkeys(buf, 'b')
1829  call WaitForAssert({-> assert_equal("TEST", term_getline(buf, 1))})
1830
1831  " clean up
1832  call StopVimInTerminal(buf)
1833endfunc
1834
1835" Test 'showcmd' behavior with a partial mapping
1836func Test_showcmd_part_map()
1837  CheckRunVimInTerminal
1838
1839  let lines =<< trim END
1840    set notimeout showcmd
1841    nnoremap ,a <Ignore>
1842    nnoremap ;a <Ignore>
1843    nnoremap Àa <Ignore>
1844    nnoremap Ëa <Ignore>
1845    nnoremap βa <Ignore>
1846    nnoremap ωa <Ignore>
1847    nnoremap …a <Ignore>
1848    nnoremap <C-W>a <Ignore>
1849  END
1850  call writefile(lines, 'Xtest_showcmd_part_map', 'D')
1851  let buf = RunVimInTerminal('-S Xtest_showcmd_part_map', #{rows: 6})
1852
1853  call term_sendkeys(buf, ":set noruler | echo\<CR>")
1854  call WaitForAssert({-> assert_equal('', term_getline(buf, 6))})
1855
1856  for c in [',', ';', 'À', 'Ë', 'β', 'ω', '…']
1857    call term_sendkeys(buf, c)
1858    call WaitForAssert({-> assert_equal(c, trim(term_getline(buf, 6)))})
1859    call term_sendkeys(buf, 'a')
1860    call WaitForAssert({-> assert_equal('', trim(term_getline(buf, 6)))})
1861  endfor
1862
1863  call term_sendkeys(buf, "\<C-W>")
1864  call WaitForAssert({-> assert_equal('^W', trim(term_getline(buf, 6)))})
1865  call term_sendkeys(buf, 'a')
1866  call WaitForAssert({-> assert_equal('', trim(term_getline(buf, 6)))})
1867
1868  " Use feedkeys() as terminal buffer cannot forward unsimplified Ctrl-W.
1869  " This is like typing Ctrl-W with modifyOtherKeys enabled.
1870  call term_sendkeys(buf, ':call feedkeys("\<*C-W>", "m")' .. " | echo\<CR>")
1871  call WaitForAssert({-> assert_equal('^W', trim(term_getline(buf, 6)))})
1872  call term_sendkeys(buf, 'a')
1873  call WaitForAssert({-> assert_equal('', trim(term_getline(buf, 6)))})
1874
1875  call StopVimInTerminal(buf)
1876endfunc
1877
1878func Test_using_past_typeahead()
1879  nnoremap :00 0
1880  exe "norm :set \x80\xfb0=0\<CR>"
1881  exe "sil norm :0\x0f\<C-U>\<CR>"
1882
1883  exe "norm :set \x80\xfb0=\<CR>"
1884  nunmap :00
1885endfunc
1886
1887
1888" vim: shiftwidth=2 sts=2 expandtab