Close A Neovim Window With The API

Code
-- doesn't force close
vim.api.nvim_win_close(WINDOW_ID, {})
Code
Code
-- forces close
vim.api.nvim_win_close(WINDOW_ID, { force=true })
Code
-- (get the id with `vim.api.nvim_set_current_win()`
-- Closes the window (like |:close| with a |window-ID|).

nvim_win_close({window}, {force})


Attributes:
    not allowed when |textlock| is active

Parameters:
    {window}  Window handle, or 0 for current window
    {force}   Behave like `:close!` The last window of a
              buffer with unwritten changes can be closed. The
              buffer will become hidden, even if 'hidden' is
              not set.

Reference