mapping_spec.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. -- Test for mappings and abbreviations
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
  4. local feed_command, expect, poke_eventloop = helpers.feed_command, helpers.expect, helpers.poke_eventloop
  5. describe('mapping', function()
  6. before_each(clear)
  7. it('abbreviations with р (0x80)', function()
  8. insert([[
  9. test starts here:
  10. ]])
  11. -- Abbreviations with р (0x80) should work.
  12. feed_command('inoreab чкпр vim')
  13. feed('GAчкпр <esc>')
  14. expect([[
  15. test starts here:
  16. vim ]])
  17. end)
  18. it('Ctrl-c works in Insert mode', function()
  19. -- Mapping of ctrl-c in insert mode
  20. feed_command('set cpo-=< cpo-=k')
  21. feed_command('inoremap <c-c> <ctrl-c>')
  22. feed_command('cnoremap <c-c> dummy')
  23. feed_command('cunmap <c-c>')
  24. feed('GA<cr>')
  25. feed('TEST2: CTRL-C |')
  26. poke_eventloop()
  27. feed('<c-c>A|<cr><esc>')
  28. poke_eventloop()
  29. feed_command('unmap <c-c>')
  30. feed_command('unmap! <c-c>')
  31. expect([[
  32. TEST2: CTRL-C |<ctrl-c>A|
  33. ]])
  34. end)
  35. it('Ctrl-c works in Visual mode', function()
  36. feed_command([[vnoremap <c-c> :<C-u>$put ='vmap works'<cr>]])
  37. feed('GV')
  38. -- XXX: For some reason the mapping is only triggered
  39. -- when <C-c> is in a separate feed command.
  40. poke_eventloop()
  41. feed('<c-c>')
  42. feed_command('vunmap <c-c>')
  43. expect([[
  44. vmap works]])
  45. end)
  46. it('langmap', function()
  47. -- langmap should not get remapped in insert mode.
  48. feed_command('inoremap { FAIL_ilangmap')
  49. feed_command('set langmap=+{ langnoremap')
  50. feed('o+<esc>')
  51. -- Insert mode expr mapping with langmap.
  52. feed_command('inoremap <expr> { "FAIL_iexplangmap"')
  53. feed('o+<esc>')
  54. -- langmap should not get remapped in cmdline mode.
  55. feed_command('cnoremap { FAIL_clangmap')
  56. feed('o+<esc>')
  57. feed_command('cunmap {')
  58. -- cmdline mode expr mapping with langmap.
  59. feed_command('cnoremap <expr> { "FAIL_cexplangmap"')
  60. feed('o+<esc>')
  61. feed_command('cunmap {')
  62. -- Assert buffer contents.
  63. expect([[
  64. +
  65. +
  66. +
  67. +]])
  68. end)
  69. it('feedkeys', function()
  70. insert([[
  71. a b c d
  72. a b c d
  73. ]])
  74. -- Vim's issue #212 (feedkeys insert mapping at current position)
  75. feed_command('nnoremap . :call feedkeys(".", "in")<cr>')
  76. feed('/^a b<cr>')
  77. feed('0qqdw.ifoo<esc>qj0@q<esc>')
  78. feed_command('unmap .')
  79. expect([[
  80. fooc d
  81. fooc d
  82. ]])
  83. end)
  84. it('i_CTRL-G_U', function()
  85. -- <c-g>U<cursor> works only within a single line
  86. feed_command('imapclear')
  87. feed_command('imap ( ()<c-g>U<left>')
  88. feed('G2o<esc>ki<cr>Test1: text with a (here some more text<esc>k.')
  89. -- test undo
  90. feed('G2o<esc>ki<cr>Test2: text wit a (here some more text [und undo]<c-g>u<esc>k.u')
  91. feed_command('imapclear')
  92. feed_command('set whichwrap=<,>,[,]')
  93. feed('G3o<esc>2k')
  94. feed_command([[:exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>."]])
  95. expect([[
  96. Test1: text with a (here some more text)
  97. Test1: text with a (here some more text)
  98. Test2: text wit a (here some more text [und undo])
  99. new line here
  100. Test3: text with a (parenthesis here
  101. new line here
  102. ]])
  103. end)
  104. end)