From 3340a5edaf1ac74ef9f7dc874a66976327388941 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 30 May 2024 22:28:05 +0200 Subject: prevent NERDTree and terminal being closed with leader+q --- lua/functions.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lua/functions.lua') 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() -- cgit v1.2.3-18-g5258