If the quickfix window is open, I can close it with :cclose
. I can map that to a shortcut key:
vim.keymap.set('n', '<C-q>', ":cclose<CR>")
vim.keymap.set('n', '<C-q>', vim.cmd.cclose)
But if I write a user-defined function and try to close the window and then do some other stuff, it doesn't work:
vim.api.nvim_create_user_command('Checkit',
function()
vim.cmd.cclose()
print('đ° checking ...')
local output = vim.fn.systemlist("check some stuff here (this takes a while)")
local errors = ... -- parse output
vim.fn.setqflist(errors)
vim.cmd.copen()
end,
{ nargs = 0 }
)
The quickfix window never closes, even if the system command here takes several seconds.
How can I close the quickfix window at the beginning of this user-defined function?
:make
after settingmakeprg
anderrorfmt
?):set nolazyredraw
did not help, but addingvim.cmd.redraw()
at the beginning of my script fixed it. Thank you for pointing me in the right direction. (You may wish to add that as an answer.)makeprg
- I'm definitely duplicating it here. Thank you!