diff options
author | HampusM <hampus@hampusmat.com> | 2024-05-30 22:28:05 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-05-30 22:28:05 +0200 |
commit | 3340a5edaf1ac74ef9f7dc874a66976327388941 (patch) | |
tree | e7ba7d53e5713368fcfbf6150b618c8dfb9aec10 | |
parent | 81105f3a91cffb32ae163ab3eb2446643d95b32e (diff) |
prevent NERDTree and terminal being closed with leader+q
-rw-r--r-- | lua/functions.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lua/functions.lua b/lua/functions.lua index da238e4..6ec4658 100644 --- a/lua/functions.lua +++ b/lua/functions.lua @@ -20,6 +20,12 @@ local function set_terminal_height(height) vim.api.nvim_win_set_height(vim.g.term_win, height) end +local function get_nerdtree_win_id() + local nerdtree_win_num = vim.api.nvim_eval("g:NERDTree.GetWinNum()") + + return vim.fn.win_getid(nerdtree_win_num) +end + function _G.check_back_space() local col = vim.api.nvim_win_get_cursor(0)[2] @@ -61,9 +67,7 @@ function _G.toggle_terminal() vim.g.term_win = vim.fn.win_getid() if vim.fn.exists("g:NERDTree") and vim.api.nvim_eval("g:NERDTree.IsOpen()") then - local nerdtree_win_num = vim.api.nvim_eval("g:NERDTree.GetWinNum()") - - local nerdtree_win_id = vim.fn.win_getid(nerdtree_win_num) + local nerdtree_win_id = get_nerdtree_win_id() vim.api.nvim_win_call( nerdtree_win_id, @@ -96,6 +100,12 @@ function _G.remove_hidden_windowless_buffers() end function _G.close_current_buffer() + local curr_win_id = vim.fn.win_getid() + + if curr_win_id == vim.g.term_win or curr_win_id == get_nerdtree_win_id() then + return + end + local current_buf_nr = vim.fn.bufnr() local all_buffers = vim.fn.getbufinfo() |