Add tabs module

This commit is contained in:
2022-01-22 14:28:12 +03:00
parent 718e3e3a06
commit 238ff216d2
2 changed files with 27 additions and 2 deletions

View File

@@ -33,8 +33,9 @@ nmap("Tv", ":lua open_terminal(true)<CR>") -- Shift+t+v - open terminal in verti
-- Tabs -- Tabs
nmap("H", ":tabprev<CR>") -- Shift+h - open previous tab nmap("H", ":tabprev<CR>") -- Shift+h - open previous tab
nmap("L", ":tabnext<CR>") -- Shift+l - open next tab nmap("L", ":tabnext<CR>") -- Shift+l - open next tab
nmap("<C-t>", ":tabnew<CR>") -- Control+t - open new empty tab nmap("tn", ":tabnew<CR>") -- Control+t - open new empty tab
nmap("<C-w>", ":tabclose<CR>") -- Control+w - close current tab nmap("tc", ":lua require('user.tabs').close_tab()<CR>") -- Control+w - close current tab
nmap("tr", ":lua require('user.tabs').restore_tab()<CR>") -- Control+Shift+t - reopen closed tab
nmap("<A-h>", ":-tabmove<CR>") -- Switch current tab with previous one nmap("<A-h>", ":-tabmove<CR>") -- Switch current tab with previous one
nmap("<A-l>", ":+tabmove<CR>") -- Switch current tab with next one nmap("<A-l>", ":+tabmove<CR>") -- Switch current tab with next one

View File

@@ -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