Switch to last-active tab in VIM

吃可爱长大的小学妹 提交于 2019-12-20 08:47:03

问题


In Vim, is there a way to quickly toggle between the current tab and the last active tab? Sort of the way '' toggles between the current line and the last active line. Plugins / keyboard mappings / voodoo all acceptable.


回答1:


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 mode, type \tl to swap to the tab you viewed last.




回答2:


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>



回答3:


I use buffers and not tabs, but I am able to switch between the current and latest used buffer using :b#
Basics of using buffers 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 



回答4:


I think what you need is the command :tablast



来源:https://stackoverflow.com/questions/2119754/switch-to-last-active-tab-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!