vim-patch:8.2.2128: there is no way to do something on CTRL-Z (#39440)

Problem:    There is no way to do something on CTRL-Z.
Solution:   Add VimSuspend and VimResume autocommand events. (closes vim/vim#7450)

100118c73a

----

Nvim implemented these events first and has enough tests.
test_suspend.vim relies on Vim 'terminal' feature.
Treat it as N/A even if all tests could be ported as Lua functional
screen/terminal tests.

----

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
Jan Edmund Lazo
2026-04-26 23:57:01 -04:00
committed by GitHub
parent f69aadd2b4
commit 689c824ef7
3 changed files with 2 additions and 64 deletions

View File

@@ -116,6 +116,7 @@ src/testdir/test_remote.vim
src/testdir/test_restricted.vim
src/testdir/test_short_sleep.py
src/testdir/test_shortpathname.vim
src/testdir/test_suspend.vim
src/testdir/test_tcl.vim
src/testdir/test_termencoding.vim
src/testdir/test_xdg.vim

View File

@@ -5178,7 +5178,7 @@ static void nv_suspend(cmdarg_T *cap)
if (VIsual_active) {
end_visual_mode(); // stop Visual mode
}
do_cmdline_cmd("st");
do_cmdline_cmd("stop");
}
/// "gv": Reselect the previous Visual area. If Visual already active,

View File

@@ -1,63 +0,0 @@
" Test :suspend
source shared.vim
source term_util.vim
func CheckSuspended(buf, fileExists)
call WaitForAssert({-> assert_match('[$#] $', term_getline(a:buf, '.'))})
if a:fileExists
call assert_equal(['foo'], readfile('Xfoo'))
else
" Without 'autowrite', buffer should not be written.
call assert_equal(0, filereadable('Xfoo'))
endif
call term_sendkeys(a:buf, "fg\<CR>\<C-L>")
call WaitForAssert({-> assert_equal(' 1 foo', term_getline(a:buf, '.'))})
endfunc
func Test_suspend()
if !has('terminal') || !executable('/bin/sh')
return
endif
let buf = term_start('/bin/sh')
" Wait for shell prompt.
call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
call term_sendkeys(buf, GetVimCommandClean()
\ . " -X"
\ . " -c 'set nu'"
\ . " -c 'call setline(1, \"foo\")'"
\ . " Xfoo\<CR>")
" Cursor in terminal buffer should be on first line in spawned vim.
call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))})
for suspend_cmd in [":suspend\<CR>",
\ ":stop\<CR>",
\ ":suspend!\<CR>",
\ ":stop!\<CR>",
\ "\<C-Z>"]
" Suspend and wait for shell prompt.
call term_sendkeys(buf, suspend_cmd)
call CheckSuspended(buf, 0)
endfor
" Test that :suspend! with 'autowrite' writes content of buffers if modified.
call term_sendkeys(buf, ":set autowrite\<CR>")
call assert_equal(0, filereadable('Xfoo'))
call term_sendkeys(buf, ":suspend\<CR>")
" Wait for shell prompt.
call CheckSuspended(buf, 1)
" Quit gracefully to dump coverage information.
call term_sendkeys(buf, ":qall!\<CR>")
call TermWait(buf)
" Wait until Vim actually exited and shell shows a prompt
call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
call StopShellInTerminal(buf)
exe buf . 'bwipe!'
call delete('Xfoo')
endfunc