Add tabs module
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
24
config/nvim/lua/user/tabs.lua
Normal file
24
config/nvim/lua/user/tabs.lua
Normal 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
|
||||||
Reference in New Issue
Block a user