From 238ff216d2907a3009804609c0b95581f214061c Mon Sep 17 00:00:00 2001 From: Daniil Tsivinsky Date: Sat, 22 Jan 2022 14:28:12 +0300 Subject: [PATCH] Add tabs module --- config/nvim/lua/user/remaps.lua | 5 +++-- config/nvim/lua/user/tabs.lua | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 config/nvim/lua/user/tabs.lua diff --git a/config/nvim/lua/user/remaps.lua b/config/nvim/lua/user/remaps.lua index e68e844..5534e4d 100644 --- a/config/nvim/lua/user/remaps.lua +++ b/config/nvim/lua/user/remaps.lua @@ -33,8 +33,9 @@ nmap("Tv", ":lua open_terminal(true)") -- Shift+t+v - open terminal in verti -- Tabs nmap("H", ":tabprev") -- Shift+h - open previous tab nmap("L", ":tabnext") -- Shift+l - open next tab -nmap("", ":tabnew") -- Control+t - open new empty tab -nmap("", ":tabclose") -- Control+w - close current tab +nmap("tn", ":tabnew") -- Control+t - open new empty tab +nmap("tc", ":lua require('user.tabs').close_tab()") -- Control+w - close current tab +nmap("tr", ":lua require('user.tabs').restore_tab()") -- Control+Shift+t - reopen closed tab nmap("", ":-tabmove") -- Switch current tab with previous one nmap("", ":+tabmove") -- Switch current tab with next one diff --git a/config/nvim/lua/user/tabs.lua b/config/nvim/lua/user/tabs.lua new file mode 100644 index 0000000..949a924 --- /dev/null +++ b/config/nvim/lua/user/tabs.lua @@ -0,0 +1,24 @@ +local M = { + history = {}, +} + +M.close_tab = function() + table.insert(M.history, vim.fn.bufnr("%")) + vim.cmd("tabclose") +end + +M.restore_tab = function() + local buflen = #M.history + + if buflen == 0 then + print("No buffers remaining") + return + end + + local buf = M.history[buflen] + vim.cmd("tabnew +" .. tostring(buf) .. "buf") + + table.remove(M.history, buflen) +end + +return M