[ACCEPTED]-Switch to last-active tab in VIM-tabs
Accepted answer
Put this in your .vimrc:
if !exists('g:lasttab')
let g:lasttab = 1
endif
nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
Then, in normal 2 mode, type \tl
to swap to the tab you viewed 1 last.
Fix the potential issue when a tab is closed:
" Switch to last-active tab
if !exists('g:Lasttab')
let g:Lasttab = 1
let g:Lasttab_backup = 1
endif
autocmd! TabLeave * let g:Lasttab_backup = g:Lasttab | let g:Lasttab = tabpagenr()
autocmd! TabClosed * let g:Lasttab = g:Lasttab_backup
nmap <silent> <Leader>` :exe "tabn " . g:Lasttab<cr>
0
I use buffers and not tabs, but I am able 3 to switch between the current and latest 2 used buffer using :b#
Basics of using buffers 1 are:
:e filename to open file in new buffer
:bn to go to next buffer
:bp to go to previous buffer
:bd to close current buffer
here's a solution in lua for folks that 2 uses neovim also make sure to change <A-S-b> to 1 your favorite keybinding.
-- switching to last active tab
vim.api.nvim_create_autocmd("TabLeave", {
pattern = "*",
callback = function()
vim.api.nvim_set_keymap('n', '<A-S-b>', '<cmd>tabn ' .. vim.api.nvim_tabpage_get_number(0) .. '<CR>', { noremap = true, silent = true })
end
})
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.