我怎么能改变我的位置/顺序的当前标签在Vim?例如,如果我想重新定位我的当前标签是第一个标签?
当前回答
你的意思是移动当前标签吗?这可以使用tabmove。
:tabm[ove] [N] *:tabm* *:tabmove*
Move the current tab page to after tab page N. Use zero to
make the current tab page the first one. Without N the tab
page is made the last one.
我有两个键绑定,将当前选项卡向左或向右移动。非常方便!
编辑:这是我的VIM宏。我不是一个大的ViM编码器,所以也许它可以做得更好,但这就是它对我的工作方式:
" Move current tab into the specified direction.
"
" @param direction -1 for left, 1 for right.
function! TabMove(direction)
" get number of tab pages.
let ntp=tabpagenr("$")
" move tab, if necessary.
if ntp > 1
" get number of current tab page.
let ctpn=tabpagenr()
" move left.
if a:direction < 0
let index=((ctpn-1+ntp-1)%ntp)
else
let index=(ctpn%ntp)
endif
" move tab page.
execute "tabmove ".index
endif
endfunction
在此之后,你可以绑定键,例如在你的.vimrc中:
map <F9> :call TabMove(-1)<CR>
map <F10> :call TabMove(1)<CR>
现在你可以通过按F9或F10来移动当前标签。
其他回答
我一直在寻找同样的方法,在一些帖子之后,我发现了一种比函数更简单的方法:
:execute "tabmove" tabpagenr() # Move the tab to the right
:execute "tabmove" tabpagenr() - 2 # Move the tab to the left
tabpagenr()返回实际的制表符位置,tabmove使用索引。
我将右侧映射为Ctrl+L,左侧映射为Ctrl+H:
map <C-H> :execute "tabmove" tabpagenr() - 2 <CR>
map <C-J> :execute "tabmove" tabpagenr() <CR>
你的意思是移动当前标签吗?这可以使用tabmove。
:tabm[ove] [N] *:tabm* *:tabmove*
Move the current tab page to after tab page N. Use zero to
make the current tab page the first one. Without N the tab
page is made the last one.
我有两个键绑定,将当前选项卡向左或向右移动。非常方便!
编辑:这是我的VIM宏。我不是一个大的ViM编码器,所以也许它可以做得更好,但这就是它对我的工作方式:
" Move current tab into the specified direction.
"
" @param direction -1 for left, 1 for right.
function! TabMove(direction)
" get number of tab pages.
let ntp=tabpagenr("$")
" move tab, if necessary.
if ntp > 1
" get number of current tab page.
let ctpn=tabpagenr()
" move left.
if a:direction < 0
let index=((ctpn-1+ntp-1)%ntp)
else
let index=(ctpn%ntp)
endif
" move tab page.
execute "tabmove ".index
endif
endfunction
在此之后,你可以绑定键,例如在你的.vimrc中:
map <F9> :call TabMove(-1)<CR>
map <F10> :call TabMove(1)<CR>
现在你可以通过按F9或F10来移动当前标签。
使用:tabm可以使用相对参数或零索引绝对参数重新定位制表符。
绝对的:
移动制表符到位置i::tabm i
相对:
向右移动tab i的位置::tabm +i 将tab i的位置向左移动::tabm -i
这是一个相对较新的功能。因此,如果它不起作用,请尝试更新您的vim。
下面是我的宏,使用@maybeshewill的答案的相对参数:
" Shortcuts to move between tabs with Ctrl+Shift+Left/Right
function TabLeft()
if tabpagenr() == 1
execute "tabm"
else
execute "tabm -1"
endif
endfunction
function TabRight()
if tabpagenr() == tabpagenr('$')
execute "tabm" 0
else
execute "tabm +1"
endif
endfunction
map <silent><C-S-Right> :execute TabRight()<CR>
map <silent><C-S-Left> :execute TabLeft()<CR>
它处理包装案例。
移动当前标签到第n个位置
:tabm n
其中n是一个数字,表示位置(从0开始)
左/右移动标签
我认为更好的解决方案是将选项卡向左或向右移动到当前位置,而不是计算出您希望它在的新位置的数值。
noremap <A-Left> :-tabmove<cr>
noremap <A-Right> :+tabmove<cr>
使用上面的键映射,你将能够移动当前选项卡:
向左使用:Alt + left 向右使用:Alt + right