简体   繁体   English

在gvim中使用鼠标重新排列选项卡

[英]Rearrange tabs with the mouse in gvim

Is there any way in gVim to rearrange tabs by dragging and dropping them with the mouse? gVim有没有办法通过鼠标拖放来重新排列标签? The behavior I'm looking for is that similar to tabs in Firefox and Chrome. 我正在寻找的行为类似于Firefox和Chrome中的标签。

I know that it's possible to change tab order using :tabm n but that requires figuring out exactly how many tabs in you'd like to move to. 我知道可以使用:tabm n来更改Tab键顺序,但这需要确定你想要移动到多少个选项卡。 Using the mouse would be more useful for this spatial task. 使用鼠标对此空间任务更有用。

Any methods to move tabs left/right by one position would also be useful, since one could remap keys and move tabs without thinking too hard. 任何将标签左/右移动一个位置的方法也很有用,因为可以重新映射键并移动标签而不用太费劲。

Here's what's in my vimrc regarding tabs: 这是我的vimrc中有关标签的内容:

" Move tabs with alt + left|right
nnoremap <silent> <A-Left> :execute 'silent! tabmove ' . (tabpagenr()-2)<CR>
nnoremap <silent> <A-Right> :execute 'silent! tabmove ' . tabpagenr()<CR>

Here is a function to move a tab to the left one position. 这是一个将标签移动到左侧一个位置的功能。 Put it in your vimrc file and set up your keys as you see fit (to call it longhand, :execute TabLeft() ). 把它放在你的vimrc文件中并按你认为合适的方式设置你的密钥(直接调用它, :execute TabLeft() )。

Note that these functions "roll" tabs from first to last and last to first, respectively, so moving the first tab left makes it the last tab, and moving the last tab right makes it the first tab. 请注意,这些功能分别从第一个到最后一个“滚动”选项卡,最后一个到第一个选项卡,因此向左移动第一个选项卡使其成为最后一个选项卡,向右移动最后一个选项卡使其成为第一个选项卡。

function TabLeft()
   let tab_number = tabpagenr() - 1
   if tab_number == 0
      execute "tabm" tabpagenr('$') - 1
   else
      execute "tabm" tab_number - 1
   endif
endfunction

...and to the right ......在右边

function TabRight()
   let tab_number = tabpagenr() - 1
   let last_tab_number = tabpagenr('$') - 1
   if tab_number == last_tab_number
      execute "tabm" 0
   else
      execute "tabm" tab_number + 1
   endif
endfunction

Thanks, and I have modified your code for my vimrc : 谢谢,我已经为我的vimrc修改了你的代码:

function ShiftTab(direction)
     let tab_number = tabpagenr() 
     if a:direction == 0
         if tab_number == 1
             exe 'tabm' . tabpagenr('$')
         else
             exe 'tabm' . (tab_number - 2)
         endif
     else
         if tab_number == tabpagenr('$')
             exe 'tabm ' . 0
         else
             exe 'tabm ' . tab_number
         endif
     endif
     return ''
endfunction

Then in my GVim, I map [ctrl+shift+left] to move left, [ctrl+shift+right] to move left 然后在我的GVim中,我将[ctrl + shift + left]向左移动,[ctrl + shift + right]向左移动

inoremap <silent> <C-S-Left>  <C-r>=ShiftTab(0)<CR>
inoremap <silent> <C-S-Right>  <C-r>=ShiftTab(1)<CR>

noremap <silent> <C-S-Left>  :call ShiftTab(0)<CR>
noremap <silent> <C-S-Right> :call ShiftTab(1)<CR>

chris.ritsen's solution stopped working for me in vim v7.4 so here's a simpler alternative: chris.ritsen的解决方案在vim v7.4中停止了为我工作所以这里有一个更简单的选择:

" Move tabs left/right
nnoremap <silent> <s-left> :-tabmove<cr>
nnoremap <silent> <s-right> :+tabmove<cr>

Ken Takata wrote a patch to do this https://groups.google.com/forum/#!msg/vim_dev/LnZVZYls1yk/PHQl4WNDAgAJ . Ken Takata写了一个补丁来执行此操作https://groups.google.com/forum/#!msg/vim_dev/LnZVZYls1yk/PHQl4WNDAgAJ One option is to download vim source code, aply this patch and compile. 一个选项是下载vim源代码,aply这个补丁并编译。

Move Tabs to the Left / Right 将标签移动到左/右

This doesn't involve using a mouse, but it uses very simple keymaps for gvim : 这不涉及使用鼠标,但它使用非常简单的gvim键盘映射:

noremap <A-[> :-tabmove<cr>
noremap <A-]> :+tabmove<cr>

Now you'll be able to move the current tab: 现在,您将能够移动当前选项卡:

  • To the left using: Alt + [ 在左边使用: Alt + [
  • To the right using: Alt + ] 在右边使用: Alt + ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM