mode_insert_spec.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. -- Insert-mode tests.
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
  4. local expect = helpers.expect
  5. local command = helpers.command
  6. local eq = helpers.eq
  7. local eval = helpers.eval
  8. local meths = helpers.meths
  9. describe('insert-mode', function()
  10. before_each(function()
  11. clear()
  12. end)
  13. it('CTRL-@', function()
  14. -- Inserts last-inserted text, leaves insert-mode.
  15. insert('hello')
  16. feed('i<C-@>x')
  17. expect('hellhello')
  18. -- C-Space is the same as C-@.
  19. -- CTRL-SPC inserts last-inserted text, leaves insert-mode.
  20. feed('i<C-Space>x')
  21. expect('hellhellhello')
  22. -- CTRL-A inserts last inserted text
  23. feed('i<C-A>x')
  24. expect('hellhellhellhelloxo')
  25. end)
  26. describe('Ctrl-R', function()
  27. it('works', function()
  28. command("let @@ = 'test'")
  29. feed('i<C-r>"')
  30. expect('test')
  31. end)
  32. it('works with multi-byte text', function()
  33. command("let @@ = 'påskägg'")
  34. feed('i<C-r>"')
  35. expect('påskägg')
  36. end)
  37. end)
  38. describe('Ctrl-O', function()
  39. it('enters command mode for one command', function()
  40. feed('ihello world<C-o>')
  41. feed(':let ctrlo = "test"<CR>')
  42. feed('iii')
  43. expect('hello worldiii')
  44. eq(1, eval('ctrlo ==# "test"'))
  45. end)
  46. it('re-enters insert mode at the end of the line when running startinsert', function()
  47. -- #6962
  48. feed('ihello world<C-o>')
  49. feed(':startinsert<CR>')
  50. feed('iii')
  51. expect('hello worldiii')
  52. end)
  53. it('re-enters insert mode at the beginning of the line when running startinsert', function()
  54. insert('hello world')
  55. feed('0<C-o>')
  56. feed(':startinsert<CR>')
  57. feed('aaa')
  58. expect('aaahello world')
  59. end)
  60. it('re-enters insert mode in the middle of the line when running startinsert', function()
  61. insert('hello world')
  62. feed('bi<C-o>')
  63. feed(':startinsert<CR>')
  64. feed('ooo')
  65. expect('hello oooworld')
  66. end)
  67. it("doesn't cancel Ctrl-O mode when processing event", function()
  68. feed('iHello World<c-o>')
  69. eq({mode='niI', blocking=false}, meths.get_mode()) -- fast event
  70. eq(2, eval('1+1')) -- causes K_EVENT key
  71. eq({mode='niI', blocking=false}, meths.get_mode()) -- still in ctrl-o mode
  72. feed('dd')
  73. eq({mode='i', blocking=false}, meths.get_mode()) -- left ctrl-o mode
  74. expect('') -- executed the command
  75. end)
  76. end)
  77. end)