Describe the bug
I was trying to prevent the command line window from opening without the use of <NOP> mappings. It seems I should simply be able to quit it upon CmdwinEnter, but this does not appear to be the case.
To Reproduce
The following leaves the command line window open.
$ cat test.vim
autocmd CmdwinEnter * quit
call feedkeys('q:')
$ vim -u NONE -S test.vim
Expected behavior
For the command line window to be closed by the autocmd.
Environment (please complete the following information):
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
If you're trying to quit vim right after it is entered, you will have to get the script to type ":q" and then press the "Enter" key.
If I understand what you are trying to do correctly then in the feedkeys call, have the argument as ":q\<CR>" using double quotes instead of single quotes.
Also note the change from q: to :q which I assumed was just a typo.
The \<CR> part is for Carraige Return, which simulates the Enter key.
autocmd CmdwinEnter * quit
call feedkeys(":q\<CR>")
This is what I changed the "test.vim" file to and it seemed to do what you were trying to achieve.
I'm trying to quit the command line window, not Vim.
Also note the change from q: to :q which I assumed was just a typo.
No this is just automating the opening of the command line window in my example.
Yes, I see the problem. Try this patch please:
diff --git a/src/ex_getln.c b/src/ex_getln.c index 2a601e1ea..9adb2de7c 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -4163,11 +4163,13 @@ open_cmdwin(void) invalidate_botline(); redraw_later(SOME_VALID); - /* No Ex mode here! */ + // No Ex mode here! exmode_active = 0; State = NORMAL; setmouse(); + // could be set by CmdWinEnter autocommand + cmdwin_result = 0; // Trigger CmdwinEnter autocommands. trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); @@ -4177,10 +4179,7 @@ open_cmdwin(void) i = RedrawingDisabled; RedrawingDisabled = 0; - /* - * Call the main loop until <CR> or CTRL-C is typed. - */ - cmdwin_result = 0; + // Call the main loop until <CR> or CTRL-C is typed. main_loop(TRUE, FALSE); RedrawingDisabled = i;
BTW: as a workaround you can use :au CmdWinEnter * :call feedkeys(":q\<cr>")
Thanks @chrisbra! I can confirm that patch gives me the expected behavior, as does your workaround example.
Thanks for the fix. Can this be tested?
Can this be tested?
Yes, I wondered about this and wasn't quite sure. I don't want to write a screentest, since this takes to long. Perhaps something simple, like setting a buffer local variable and testing whether that one exists? Also the buftype option could be used. I'll go with this approach.
Okay, getting the test right was harder than expected. How about this patch:
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index f2c9af50f..f25f65de4 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -2259,3 +2259,32 @@ func Test_autocmd_SafeState() call StopVimInTerminal(buf) call delete('XSafeState') endfunc + +func! Test_autocmd_CmdWinEnter() + CheckRunVimInTerminal + " There is not cmdwin switch, so + " test for cmdline_hist + " (both are available with small builds) + CheckFeature cmdline_hist + let lines =<< trim END + let b:dummy_var = 'This is a dummy' + autocmd CmdWinEnter * quit + let winnr = winnr('$') + END + let filename='XCmdWinEnter' + call writefile(lines, filename) + let buf = RunVimInTerminal('-S '.filename, #{rows: 6}) + + call term_sendkeys(buf, "q:") + call term_wait(buf) + call term_sendkeys(buf, ":echo b:dummy_var\<cr>") + call WaitForAssert({-> assert_match('^This is a dummy', term_getline(buf, 6))}, 1000) + call term_sendkeys(buf, ":echo &buftype\<cr>") + call WaitForAssert({-> assert_notmatch('^nofile', term_getline(buf, 6))}, 1000) + call term_sendkeys(buf, ":echo winnr\<cr>") + call WaitForAssert({-> assert_match('^1', term_getline(buf, 6))}, 1000) + + " clean up + call StopVimInTerminal(buf) + call delete(filename) +endfunc
Your code appears to be a combination of a test script for Vim called test_autocmd.vim and a section of the source code for Vim called ex_getln.c. It appears to be associated with testing and autocmd (autocommand) capability in Vim. Its pretty helpful though. :)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()