开发者

Switching to a particular tab in VIM

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 call开发者_如何学Ced 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?


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)


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜