2024-04-09 04:26:16 -07:00
|
|
|
local t = require('test.functional.testutil')()
|
2024-04-08 02:03:20 -07:00
|
|
|
local clear = t.clear
|
|
|
|
local feed = t.feed
|
|
|
|
local eq = t.eq
|
|
|
|
local expect = t.expect
|
|
|
|
local eval = t.eval
|
|
|
|
local fn = t.fn
|
|
|
|
local insert = t.insert
|
|
|
|
local write_file = t.write_file
|
|
|
|
local exc_exec = t.exc_exec
|
|
|
|
local command = t.command
|
2016-03-14 15:58:47 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
|
|
|
|
describe('mappings with <Cmd>', function()
|
|
|
|
local screen
|
2022-03-27 10:25:55 -07:00
|
|
|
local tmpfile = 'X_ex_cmds_cmd_map'
|
|
|
|
|
2016-03-14 15:58:47 -07:00
|
|
|
local function cmdmap(lhs, rhs)
|
2022-03-27 10:25:55 -07:00
|
|
|
command('noremap ' .. lhs .. ' <Cmd>' .. rhs .. '<cr>')
|
|
|
|
command('noremap! ' .. lhs .. ' <Cmd>' .. rhs .. '<cr>')
|
2016-03-14 15:58:47 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(65, 8)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[1] = { bold = true, foreground = Screen.colors.Blue1 },
|
|
|
|
[2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
|
|
|
|
[3] = { bold = true, foreground = Screen.colors.SeaGreen4 },
|
|
|
|
[4] = { bold = true },
|
2024-02-14 16:49:39 -07:00
|
|
|
[5] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey },
|
2016-03-14 15:58:47 -07:00
|
|
|
[6] = { foreground = Screen.colors.Blue1 },
|
2018-03-31 02:12:27 -07:00
|
|
|
[7] = { bold = true, reverse = true },
|
2018-12-01 02:35:45 -07:00
|
|
|
[8] = { background = Screen.colors.WebGray },
|
|
|
|
[9] = { background = Screen.colors.LightMagenta },
|
|
|
|
[10] = { foreground = Screen.colors.Red },
|
2016-03-14 15:58:47 -07:00
|
|
|
})
|
|
|
|
screen:attach()
|
|
|
|
|
|
|
|
cmdmap('<F3>', 'let m = mode(1)')
|
|
|
|
cmdmap('<F4>', 'normal! ww')
|
|
|
|
cmdmap('<F5>', 'normal! "ay')
|
|
|
|
cmdmap('<F6>', 'throw "very error"')
|
2022-03-27 10:25:55 -07:00
|
|
|
command([[
|
2016-03-14 15:58:47 -07:00
|
|
|
function! TextObj()
|
|
|
|
if mode() !=# "v"
|
|
|
|
normal! v
|
|
|
|
end
|
|
|
|
call cursor(1,3)
|
|
|
|
normal! o
|
|
|
|
call cursor(2,4)
|
|
|
|
endfunction]])
|
|
|
|
cmdmap('<F7>', 'call TextObj()')
|
|
|
|
insert([[
|
|
|
|
some short lines
|
|
|
|
of test text]])
|
|
|
|
feed('gg')
|
|
|
|
cmdmap('<F8>', 'startinsert')
|
|
|
|
cmdmap('<F9>', 'stopinsert')
|
2022-03-27 10:25:55 -07:00
|
|
|
command('abbr foo <Cmd>let g:y = 17<cr>bar')
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
os.remove(tmpfile)
|
2016-03-14 15:58:47 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('can be displayed', function()
|
2022-03-27 10:25:55 -07:00
|
|
|
command('map <F3>')
|
2016-03-14 15:58:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
^some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{6:<F3>} {6:*} {6:<Cmd>}let m = mode(1){6:<CR>} |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles invalid mappings', function()
|
2022-03-27 10:25:55 -07:00
|
|
|
command('let x = 0')
|
|
|
|
command('noremap <F3> <Cmd><Cmd>let x = 1<cr>')
|
2016-03-14 15:58:47 -07:00
|
|
|
feed('<F3>')
|
|
|
|
screen:expect([[
|
|
|
|
^some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2023-05-06 17:12:42 -07:00
|
|
|
{2:E1136: <Cmd> mapping must end with <CR> before second <Cmd>} |
|
2016-03-14 15:58:47 -07:00
|
|
|
]])
|
|
|
|
|
2022-04-29 05:50:14 -07:00
|
|
|
command('noremap <F3> <Cmd>let x = 3')
|
2016-03-14 15:58:47 -07:00
|
|
|
feed('<F3>')
|
|
|
|
screen:expect([[
|
|
|
|
^some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2023-05-06 17:33:06 -07:00
|
|
|
{2:E1255: <Cmd> mapping must end with <CR>} |
|
2016-03-14 15:58:47 -07:00
|
|
|
]])
|
2022-04-29 05:50:14 -07:00
|
|
|
eq(0, eval('x'))
|
|
|
|
end)
|
2016-03-14 15:58:47 -07:00
|
|
|
|
2022-04-29 05:50:14 -07:00
|
|
|
it('allows special keys and modifiers', function()
|
|
|
|
command('noremap <F3> <Cmd>normal! <Down><CR>')
|
2016-03-14 15:58:47 -07:00
|
|
|
feed('<F3>')
|
|
|
|
screen:expect([[
|
2022-04-29 05:50:14 -07:00
|
|
|
some short lines |
|
|
|
|
^of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2022-04-29 05:50:14 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
|
|
|
|
command('noremap <F3> <Cmd>normal! <C-Right><CR>')
|
|
|
|
feed('<F3>')
|
|
|
|
screen:expect([[
|
|
|
|
some short lines |
|
|
|
|
of ^test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2022-04-29 05:50:14 -07:00
|
|
|
|
|
2016-03-14 15:58:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2022-05-02 15:44:14 -07:00
|
|
|
it('handles string containing K_SPECIAL (0x80) bytes correctly', function()
|
|
|
|
command([[noremap <F3> <Cmd>let g:str = 'foo…bar'<CR>]])
|
2022-04-29 15:05:57 -07:00
|
|
|
feed('<F3>')
|
2022-05-02 15:44:14 -07:00
|
|
|
eq('foo…bar', eval('g:str'))
|
|
|
|
local str = eval([["foo\<D-…>bar"]])
|
|
|
|
command([[noremap <F3> <Cmd>let g:str = ']] .. str .. [['<CR>]])
|
|
|
|
feed('<F3>')
|
|
|
|
eq(str, eval('g:str'))
|
|
|
|
command([[noremap <F3> <Cmd>let g:str = 'foo<D-…>bar'<CR>]])
|
|
|
|
feed('<F3>')
|
|
|
|
eq(str, eval('g:str'))
|
2022-04-29 15:05:57 -07:00
|
|
|
end)
|
|
|
|
|
2016-03-14 15:58:47 -07:00
|
|
|
it('works in various modes and sees correct `mode()` value', function()
|
|
|
|
-- normal mode
|
|
|
|
feed('<F3>')
|
|
|
|
eq('n', eval('m'))
|
|
|
|
|
|
|
|
-- visual mode
|
|
|
|
feed('v<F3>')
|
|
|
|
eq('v', eval('m'))
|
|
|
|
-- didn't leave visual mode
|
|
|
|
eq('v', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- visual mapping in select mode
|
|
|
|
feed('gh<F3>')
|
|
|
|
eq('v', eval('m'))
|
|
|
|
-- didn't leave select mode
|
|
|
|
eq('s', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- select mode mapping
|
2022-03-27 10:25:55 -07:00
|
|
|
command('snoremap <F3> <Cmd>let m = mode(1)<cr>')
|
2016-03-14 15:58:47 -07:00
|
|
|
feed('gh<F3>')
|
|
|
|
eq('s', eval('m'))
|
|
|
|
-- didn't leave select mode
|
|
|
|
eq('s', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- operator-pending mode
|
|
|
|
feed('d<F3>')
|
|
|
|
eq('no', eval('m'))
|
|
|
|
-- did leave operator-pending mode
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
|
|
|
|
--insert mode
|
|
|
|
feed('i<F3>')
|
|
|
|
eq('i', eval('m'))
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- replace mode
|
|
|
|
feed('<Ins><F3>')
|
|
|
|
eq('R', eval('m'))
|
|
|
|
eq('R', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- virtual replace mode
|
|
|
|
feed('gR<F3>')
|
|
|
|
eq('Rv', eval('m'))
|
|
|
|
eq('Rv', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- langmap works, but is not distinguished in mode(1)
|
|
|
|
feed(':set iminsert=1<cr>i<F3>')
|
|
|
|
eq('i', eval('m'))
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
|
|
|
|
feed(':<F3>')
|
|
|
|
eq('c', eval('m'))
|
|
|
|
eq('c', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- terminal mode
|
2022-03-27 10:25:55 -07:00
|
|
|
command('tnoremap <F3> <Cmd>let m = mode(1)<cr>')
|
|
|
|
command('split | terminal')
|
2016-03-14 15:58:47 -07:00
|
|
|
feed('i')
|
|
|
|
eq('t', eval('mode(1)'))
|
|
|
|
feed('<F3>')
|
|
|
|
eq('t', eval('m'))
|
|
|
|
eq('t', eval('mode(1)'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('works in normal mode', function()
|
|
|
|
cmdmap('<F2>', 'let s = [mode(1), v:count, v:register]')
|
|
|
|
|
|
|
|
-- check v:count and v:register works
|
|
|
|
feed('<F2>')
|
|
|
|
eq({ 'n', 0, '"' }, eval('s'))
|
|
|
|
feed('7<F2>')
|
|
|
|
eq({ 'n', 7, '"' }, eval('s'))
|
|
|
|
feed('"e<F2>')
|
|
|
|
eq({ 'n', 0, 'e' }, eval('s'))
|
|
|
|
feed('5"k<F2>')
|
|
|
|
eq({ 'n', 5, 'k' }, eval('s'))
|
|
|
|
feed('"+2<F2>')
|
|
|
|
eq({ 'n', 2, '+' }, eval('s'))
|
|
|
|
|
|
|
|
-- text object enters visual mode
|
|
|
|
feed('<F7>')
|
|
|
|
screen:expect([[
|
|
|
|
so{5:me short lines} |
|
|
|
|
{5:of }^test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- VISUAL --} |
|
|
|
|
]])
|
|
|
|
feed('<esc>')
|
|
|
|
|
|
|
|
-- startinsert
|
|
|
|
feed('<F8>')
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
cmdmap(',a', 'call feedkeys("aalpha") \\| let g:a = getline(2)')
|
|
|
|
cmdmap(',b', 'call feedkeys("abeta", "x") \\| let g:b = getline(2)')
|
|
|
|
|
|
|
|
feed(',a<F3>')
|
|
|
|
screen:expect([[
|
|
|
|
some short lines |
|
|
|
|
of alpha^test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- INSERT --} |
|
|
|
|
]])
|
|
|
|
-- feedkeys were not executed immediately
|
|
|
|
eq({ 'n', 'of test text' }, eval('[m,a]'))
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
|
|
|
|
feed(',b<F3>')
|
|
|
|
screen:expect([[
|
|
|
|
some short lines |
|
|
|
|
of alphabet^atest text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
-- feedkeys(..., 'x') was executed immediately, but insert mode gets aborted
|
|
|
|
eq({ 'n', 'of alphabetatest text' }, eval('[m,b]'))
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('works in :normal command', function()
|
2022-03-27 10:25:55 -07:00
|
|
|
command('noremap ,x <Cmd>call append(1, "xx")\\| call append(1, "aa")<cr>')
|
|
|
|
command('noremap ,f <Cmd>nosuchcommand<cr>')
|
|
|
|
command('noremap ,e <Cmd>throw "very error"\\| call append(1, "yy")<cr>')
|
|
|
|
command('noremap ,m <Cmd>echoerr "The message."\\| call append(1, "zz")<cr>')
|
|
|
|
command(
|
|
|
|
'noremap ,w <Cmd>for i in range(5)\\|if i==1\\|echoerr "Err"\\|endif\\|call append(1, i)\\|endfor<cr>'
|
|
|
|
)
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
feed(':normal ,x<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
^some short lines |
|
|
|
|
aa |
|
|
|
|
xx |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*3
|
2019-01-15 09:50:43 -07:00
|
|
|
:normal ,x |
|
2016-03-14 15:58:47 -07:00
|
|
|
]])
|
|
|
|
|
|
|
|
eq('Vim:E492: Not an editor command: nosuchcommand', exc_exec('normal ,f'))
|
|
|
|
eq('very error', exc_exec('normal ,e'))
|
|
|
|
eq('Vim(echoerr):The message.', exc_exec('normal ,m'))
|
|
|
|
feed('w')
|
|
|
|
screen:expect([[
|
|
|
|
some ^short lines |
|
|
|
|
aa |
|
|
|
|
xx |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*3
|
2019-01-15 09:50:43 -07:00
|
|
|
:normal ,x |
|
2016-03-14 15:58:47 -07:00
|
|
|
]])
|
|
|
|
|
2022-03-27 10:25:55 -07:00
|
|
|
command(':%d')
|
2016-03-14 15:58:47 -07:00
|
|
|
eq('Vim(echoerr):Err', exc_exec('normal ,w'))
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
0 |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
--No lines in buffer-- |
|
|
|
|
]])
|
|
|
|
|
2022-03-27 10:25:55 -07:00
|
|
|
command(':%d')
|
|
|
|
feed(':normal ,w<cr>')
|
2016-03-14 15:58:47 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
4 |
|
|
|
|
3 |
|
|
|
|
2 |
|
|
|
|
1 |
|
|
|
|
0 |
|
|
|
|
{1:~ }|
|
|
|
|
{2:Err} |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('works in visual mode', function()
|
|
|
|
-- can extend visual mode
|
|
|
|
feed('v<F4>')
|
|
|
|
screen:expect([[
|
|
|
|
{5:some short }^lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- VISUAL --} |
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('v', fn.mode(1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
-- can invoke operator, ending visual mode
|
|
|
|
feed('<F5>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('n', fn.mode(1))
|
|
|
|
eq({ 'some short l' }, fn.getreg('a', 1, 1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
-- error doesn't interrupt visual mode
|
|
|
|
feed('ggvw<F6>')
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
{5:some }short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2018-03-31 02:12:27 -07:00
|
|
|
{7: }|
|
2016-03-14 15:58:47 -07:00
|
|
|
{2:Error detected while processing :} |
|
|
|
|
{2:E605: Exception not caught: very error} |
|
|
|
|
{3:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
|
|
|
feed('<cr>')
|
|
|
|
eq('E605: Exception not caught: very error', eval('v:errmsg'))
|
|
|
|
-- still in visual mode, <cr> was consumed by the error prompt
|
|
|
|
screen:expect([[
|
|
|
|
{5:some }^short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- VISUAL --} |
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('v', fn.mode(1))
|
2016-03-14 15:58:47 -07:00
|
|
|
feed('<F7>')
|
|
|
|
screen:expect([[
|
|
|
|
so{5:me short lines} |
|
|
|
|
{5:of }^test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- VISUAL --} |
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('v', fn.mode(1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
-- startinsert gives "-- (insert) VISUAL --" mode
|
|
|
|
feed('<F8>')
|
|
|
|
screen:expect([[
|
|
|
|
so{5:me short lines} |
|
|
|
|
{5:of }^test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- (insert) VISUAL --} |
|
|
|
|
]])
|
|
|
|
eq('v', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('works in select mode', function()
|
2022-03-27 10:25:55 -07:00
|
|
|
command('snoremap <F1> <cmd>throw "very error"<cr>')
|
|
|
|
command('snoremap <F2> <cmd>normal! <c-g>"by<cr>')
|
2016-03-14 15:58:47 -07:00
|
|
|
-- can extend select mode
|
|
|
|
feed('gh<F4>')
|
|
|
|
screen:expect([[
|
|
|
|
{5:some short }^lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- SELECT --} |
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('s', fn.mode(1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
2023-09-15 00:43:48 -07:00
|
|
|
-- visual mapping in select mode restart select mode after operator
|
2016-03-14 15:58:47 -07:00
|
|
|
feed('<F5>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('s', fn.mode(1))
|
|
|
|
eq({ 'some short l' }, fn.getreg('a', 1, 1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
-- select mode mapping works, and does not restart select mode
|
|
|
|
feed('<F2>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('n', fn.mode(1))
|
|
|
|
eq({ 'some short l' }, fn.getreg('b', 1, 1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
-- error doesn't interrupt temporary visual mode
|
|
|
|
feed('<esc>ggvw<c-g><F6>')
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
{5:some }short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2018-03-31 02:12:27 -07:00
|
|
|
{7: }|
|
2016-03-14 15:58:47 -07:00
|
|
|
{2:Error detected while processing :} |
|
|
|
|
{2:E605: Exception not caught: very error} |
|
|
|
|
{3:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
|
|
|
feed('<cr>')
|
|
|
|
eq('E605: Exception not caught: very error', eval('v:errmsg'))
|
|
|
|
-- still in visual mode, <cr> was consumed by the error prompt
|
|
|
|
screen:expect([[
|
|
|
|
{5:some }^short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- VISUAL --} |
|
|
|
|
]])
|
|
|
|
-- quirk: restoration of select mode is not performed
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('v', fn.mode(1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
-- error doesn't interrupt select mode
|
|
|
|
feed('<esc>ggvw<c-g><F1>')
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
{5:some }short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2018-03-31 02:12:27 -07:00
|
|
|
{7: }|
|
2016-03-14 15:58:47 -07:00
|
|
|
{2:Error detected while processing :} |
|
|
|
|
{2:E605: Exception not caught: very error} |
|
|
|
|
{3:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
|
|
|
feed('<cr>')
|
|
|
|
eq('E605: Exception not caught: very error', eval('v:errmsg'))
|
|
|
|
-- still in select mode, <cr> was consumed by the error prompt
|
|
|
|
screen:expect([[
|
|
|
|
{5:some }^short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- SELECT --} |
|
|
|
|
]])
|
|
|
|
-- quirk: restoration of select mode is not performed
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('s', fn.mode(1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
feed('<F7>')
|
|
|
|
screen:expect([[
|
|
|
|
so{5:me short lines} |
|
|
|
|
{5:of }^test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- SELECT --} |
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('s', fn.mode(1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
-- startinsert gives "-- SELECT (insert) --" mode
|
|
|
|
feed('<F8>')
|
|
|
|
screen:expect([[
|
|
|
|
so{5:me short lines} |
|
|
|
|
{5:of }^test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- (insert) SELECT --} |
|
|
|
|
]])
|
|
|
|
eq('s', eval('mode(1)'))
|
|
|
|
feed('<esc>')
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('works in operator-pending mode', function()
|
|
|
|
feed('d<F4>')
|
|
|
|
expect([[
|
|
|
|
lines
|
|
|
|
of test text]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 'some short ' }, fn.getreg('"', 1, 1))
|
2016-03-14 15:58:47 -07:00
|
|
|
feed('.')
|
|
|
|
expect([[
|
|
|
|
test text]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 'lines', 'of ' }, fn.getreg('"', 1, 1))
|
2016-03-14 15:58:47 -07:00
|
|
|
feed('uu')
|
|
|
|
expect([[
|
|
|
|
some short lines
|
|
|
|
of test text]])
|
|
|
|
|
|
|
|
-- error aborts operator-pending, operator not performed
|
|
|
|
feed('d<F6>')
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2018-03-31 02:12:27 -07:00
|
|
|
{7: }|
|
2016-03-14 15:58:47 -07:00
|
|
|
{2:Error detected while processing :} |
|
|
|
|
{2:E605: Exception not caught: very error} |
|
|
|
|
{3:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
|
|
|
feed('<cr>')
|
|
|
|
eq('E605: Exception not caught: very error', eval('v:errmsg'))
|
|
|
|
expect([[
|
|
|
|
some short lines
|
|
|
|
of test text]])
|
|
|
|
|
|
|
|
feed('"bd<F7>')
|
|
|
|
expect([[
|
|
|
|
soest text]])
|
2024-03-11 07:23:14 -07:00
|
|
|
eq({ 'me short lines', 'of t' }, fn.getreg('b', 1, 1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
-- startinsert aborts operator
|
|
|
|
feed('d<F8>')
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
expect([[
|
|
|
|
soest text]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('works in insert mode', function()
|
|
|
|
-- works the same as <c-o>w<c-o>w
|
|
|
|
feed('iindeed <F4>little ')
|
|
|
|
screen:expect([[
|
|
|
|
indeed some short little ^lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- INSERT --} |
|
|
|
|
]])
|
|
|
|
|
|
|
|
feed('<F6>')
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
indeed some short little lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2018-03-31 02:12:27 -07:00
|
|
|
{7: }|
|
2016-03-14 15:58:47 -07:00
|
|
|
{2:Error detected while processing :} |
|
|
|
|
{2:E605: Exception not caught: very error} |
|
|
|
|
{3:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
|
|
|
|
|
|
|
feed('<cr>')
|
|
|
|
eq('E605: Exception not caught: very error', eval('v:errmsg'))
|
|
|
|
-- still in insert
|
|
|
|
screen:expect([[
|
|
|
|
indeed some short little ^lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- INSERT --} |
|
|
|
|
]])
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- When entering visual mode from InsertEnter autocmd, an async event, or
|
|
|
|
-- a <cmd> mapping, vim ends up in undocumented "INSERT VISUAL" mode. If a
|
|
|
|
-- vim patch decides to disable this mode, this test is expected to fail.
|
|
|
|
feed('<F7>stuff ')
|
|
|
|
screen:expect([[
|
|
|
|
in{5:deed some short little lines} |
|
|
|
|
{5:of stuff }^test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- INSERT VISUAL --} |
|
|
|
|
]])
|
|
|
|
expect([[
|
|
|
|
indeed some short little lines
|
|
|
|
of stuff test text]])
|
|
|
|
|
|
|
|
feed('<F5>')
|
2024-03-11 07:23:14 -07:00
|
|
|
eq({ 'deed some short little lines', 'of stuff t' }, fn.getreg('a', 1, 1))
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
-- still in insert
|
|
|
|
screen:expect([[
|
|
|
|
in^deed some short little lines |
|
|
|
|
of stuff test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- INSERT --} |
|
|
|
|
]])
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- also works as part of abbreviation
|
|
|
|
feed('<space>foo ')
|
|
|
|
screen:expect([[
|
|
|
|
in bar ^deed some short little lines |
|
|
|
|
of stuff test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- INSERT --} |
|
|
|
|
]])
|
|
|
|
eq(17, eval('g:y'))
|
|
|
|
|
|
|
|
-- :startinsert does nothing
|
|
|
|
feed('<F8>')
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
|
|
|
|
-- :stopinsert works
|
|
|
|
feed('<F9>')
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
end)
|
|
|
|
|
2018-12-01 02:35:45 -07:00
|
|
|
it('works in insert completion (Ctrl-X) mode', function()
|
|
|
|
feed('os<c-x><c-n>')
|
|
|
|
screen:expect([[
|
|
|
|
some short lines |
|
|
|
|
some^ |
|
|
|
|
{8:some } |
|
|
|
|
{9:short }{1: }|
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*3
|
2018-12-01 02:35:45 -07:00
|
|
|
{4:-- Keyword Local completion (^N^P) }{3:match 1 of 2} |
|
|
|
|
]])
|
|
|
|
|
|
|
|
feed('<f3>')
|
|
|
|
eq('ic', eval('m'))
|
|
|
|
|
|
|
|
-- ensure a redraw, this would have moved the cursor
|
|
|
|
-- instead if CTRL-X mode was left.
|
|
|
|
feed('<up>')
|
|
|
|
screen:expect([[
|
|
|
|
some short lines |
|
|
|
|
some^ |
|
|
|
|
{9:some } |
|
|
|
|
{9:short }{1: }|
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*3
|
2018-12-01 02:35:45 -07:00
|
|
|
{4:-- Keyword Local completion (^N^P) }{10:Back at original} |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2016-03-14 15:58:47 -07:00
|
|
|
it('works in cmdline mode', function()
|
|
|
|
feed(':text<F3>')
|
|
|
|
eq('c', eval('m'))
|
|
|
|
-- didn't leave cmdline mode
|
|
|
|
eq('c', eval('mode(1)'))
|
|
|
|
feed('<cr>')
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
screen:expect([[
|
|
|
|
^some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{2:E492: Not an editor command: text} |
|
|
|
|
]])
|
|
|
|
|
|
|
|
feed(':echo 2<F6>')
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
some short lines |
|
|
|
|
of test text |
|
2016-03-14 15:58:47 -07:00
|
|
|
{1:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{7: }|
|
2016-03-14 15:58:47 -07:00
|
|
|
:echo 2 |
|
|
|
|
{2:Error detected while processing :} |
|
|
|
|
{2:E605: Exception not caught: very error} |
|
|
|
|
:echo 2^ |
|
|
|
|
]])
|
|
|
|
eq('E605: Exception not caught: very error', eval('v:errmsg'))
|
|
|
|
-- didn't leave cmdline mode
|
|
|
|
eq('c', eval('mode(1)'))
|
|
|
|
feed('+2<cr>')
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
some short lines |
|
|
|
|
of test text |
|
|
|
|
{7: }|
|
2016-03-14 15:58:47 -07:00
|
|
|
:echo 2 |
|
|
|
|
{2:Error detected while processing :} |
|
|
|
|
{2:E605: Exception not caught: very error} |
|
|
|
|
4 |
|
|
|
|
{3:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
|
|
|
-- however, message scrolling may cause extra CR prompt
|
|
|
|
-- This is consistent with output from async events.
|
|
|
|
feed('<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
^some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
eq('n', eval('mode(1)'))
|
|
|
|
|
|
|
|
feed(':let g:x = 3<F4>')
|
|
|
|
screen:expect([[
|
|
|
|
some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
:let g:x = 3^ |
|
|
|
|
]])
|
|
|
|
feed('+2<cr>')
|
|
|
|
-- cursor was moved in the background
|
|
|
|
screen:expect([[
|
|
|
|
some short ^lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
:let g:x = 3+2 |
|
|
|
|
]])
|
|
|
|
eq(5, eval('g:x'))
|
|
|
|
|
|
|
|
feed(':let g:y = 7<F8>')
|
|
|
|
screen:expect([[
|
|
|
|
some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
:let g:y = 7^ |
|
|
|
|
]])
|
|
|
|
eq('c', eval('mode(1)'))
|
|
|
|
feed('+2<cr>')
|
|
|
|
-- startinsert takes effect after leaving cmdline mode
|
|
|
|
screen:expect([[
|
|
|
|
some short ^lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2016-03-14 15:58:47 -07:00
|
|
|
{4:-- INSERT --} |
|
|
|
|
]])
|
|
|
|
eq('i', eval('mode(1)'))
|
|
|
|
eq(9, eval('g:y'))
|
|
|
|
end)
|
|
|
|
|
2018-08-15 05:14:46 -07:00
|
|
|
it("doesn't crash when invoking cmdline mode recursively #8859", function()
|
|
|
|
cmdmap('<F2>', 'norm! :foo')
|
|
|
|
feed(':bar')
|
|
|
|
screen:expect([[
|
|
|
|
some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2018-08-15 05:14:46 -07:00
|
|
|
:bar^ |
|
|
|
|
]])
|
|
|
|
|
|
|
|
feed('<f2>x')
|
|
|
|
screen:expect([[
|
|
|
|
some short lines |
|
|
|
|
of test text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2018-08-15 05:14:46 -07:00
|
|
|
:barx^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2018-09-08 00:23:19 -07:00
|
|
|
it('works with <SID> mappings', function()
|
2022-03-27 10:25:55 -07:00
|
|
|
command('new!')
|
|
|
|
write_file(
|
|
|
|
tmpfile,
|
|
|
|
[[
|
2018-09-08 00:23:19 -07:00
|
|
|
map <f2> <Cmd>call <SID>do_it()<Cr>
|
|
|
|
function! s:do_it()
|
|
|
|
let g:x = 10
|
|
|
|
endfunction
|
|
|
|
]]
|
|
|
|
)
|
2022-03-27 10:25:55 -07:00
|
|
|
command('source ' .. tmpfile)
|
2018-09-08 00:23:19 -07:00
|
|
|
feed('<f2>')
|
|
|
|
eq('', eval('v:errmsg'))
|
|
|
|
eq(10, eval('g:x'))
|
|
|
|
end)
|
2016-03-14 15:58:47 -07:00
|
|
|
end)
|