Switching to a particular tab in VIM

半城伤御伤魂 提交于 2019-12-29 02:46:44

问题


I was trying to switch from a tab to another tab (which may not be adjacent to the previous tab) in VIM. Is there any shortcut for that, like we have Ctrl-p/Ctrl-n for switching to adjacent tabs?

Also, I was trying to write a key mapping which will give a variable as input to a function and do the operation. For instance, let's say I press Ctrl-5 and a function (written by the user) will be called and given as input 5, and the cursor will go to tab 5 (if there is any 5th tab opened).

Can you please suggest how this can be done?


回答1:


use 5gt to switch to tab 5

:tabn[ext] {count}

{count}gt

Go to tab page {count}. The first tab page has number one.

you can also bind it to a key:

:map <C-5> 5gt
:imap <C-5> <C-O>5gt

(Mapping Ctrl-<number> could be different/impossible for some terminals. Consider Alt-<number> then)




回答2:


Tackling only your first question, and quoting from help tabs in vim:

{count}gt       Go to tab page {count}.  The first tab page has number one.
{count}gT       Go {count} tab pages back.  Wraps around from the first one
                to the last one.

ie, typing 3gt goes to the third tab, 3gT goes 3 tabs back from the current tab.




回答3:


Just for sharing the key mapping to jump into particular tab directly. Please put them into _vimrc and make it work.

" Jump to particular tab directly
"NORMAL mode bindings for gvim
noremap <unique> <M-1> 1gt
noremap <unique> <M-2> 2gt
noremap <unique> <M-3> 3gt
noremap <unique> <M-4> 4gt
noremap <unique> <M-5> 5gt
noremap <unique> <M-6> 6gt
noremap <unique> <M-7> 7gt
noremap <unique> <M-8> 8gt
noremap <unique> <M-9> 9gt
noremap <unique> <M-0> 10gt

"INSERT mode bindings for gvim
inoremap <unique> <M-1> <C-O>1gt
inoremap <unique> <M-2> <C-O>2gt
inoremap <unique> <M-3> <C-O>3gt
inoremap <unique> <M-4> <C-O>4gt
inoremap <unique> <M-5> <C-O>5gt
inoremap <unique> <M-6> <C-O>6gt
inoremap <unique> <M-7> <C-O>7gt
inoremap <unique> <M-8> <C-O>8gt
inoremap <unique> <M-9> <C-O>9gt
inoremap <unique> <M-0> <C-O>10gt


来源:https://stackoverflow.com/questions/2005214/switching-to-a-particular-tab-in-vim

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