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

发布于 2024-08-18 18:31:17 字数 217 浏览 4 评论 0原文

gVim 有没有办法通过用鼠标拖放选项卡来重新排列选项卡?我正在寻找的行为类似于 Firefox 和 Chrome 中的选项卡。

我知道可以使用 :tabm n 更改选项卡顺序,但这需要弄清楚您想要移动到多少个选项卡。对于这个空间任务来说,使用鼠标会更有用。

任何将选项卡向左/向右移动一个位置的方法也将很有用,因为人们可以重新映射键并移动选项卡而无需费力思考。

Is there any way in gVim to rearrange tabs by dragging and dropping them with the mouse? The behavior I'm looking for is that similar to tabs in Firefox and 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. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

冰火雁神 2024-08-25 18:31:17

以下是我的 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's what's in my vimrc regarding tabs:

" 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>
爱情眠于流年 2024-08-25 18:31:17

这是一个将选项卡向左移动一个位置的函数。将其放入您的 vimrc 文件中并按照您认为合适的方式设置键(普通调用它,:execute TabLeft())。

请注意,这些函数分别从第一个到最后一个和从最后一个到第一个“滚动”选项卡,因此向左移动第一个选项卡使其成为最后一个选项卡,向右移动最后一个选项卡使其成为第一个选项卡。

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

...然后向右

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

...然后向右


) - 1
   if tab_number == last_tab_number
      execute "tabm" 0
   else
      execute "tabm" tab_number + 1
   endif
endfunction
) - 1 else execute "tabm" tab_number - 1 endif endfunction

...然后向右

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()).

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('

...and to the right

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

...and to the right


) - 1
   if tab_number == last_tab_number
      execute "tabm" 0
   else
      execute "tabm" tab_number + 1
   endif
endfunction
) - 1 else execute "tabm" tab_number - 1 endif endfunction

...and to the right

_畞蕅 2024-08-25 18:31:17

谢谢,我已经修改了你的 vimrc 代码:

function ShiftTab(direction)
     let tab_number = tabpagenr() 
     if a:direction == 0
         if tab_number == 1
             exe 'tabm' . tabpagenr('

然后在我的 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>
) else exe 'tabm' . (tab_number - 2) endif else if tab_number == tabpagenr('

然后在我的 GVim 中,我映射 [ctrl+shift+left] 向左移动,[ctrl+shift+right] 向左移动


)
             exe 'tabm ' . 0
         else
             exe 'tabm ' . tab_number
         endif
     endif
     return ''
endfunction

然后在我的 GVim 中,我映射 [ctrl+shift+left] 向左移动,[ctrl+shift+right] 向左移动

Thanks, and I have modified your code for my vimrc :

function ShiftTab(direction)
     let tab_number = tabpagenr() 
     if a:direction == 0
         if tab_number == 1
             exe 'tabm' . tabpagenr('

Then in my GVim, I map [ctrl+shift+left] to move left, [ctrl+shift+right] to move left

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>
) else exe 'tabm' . (tab_number - 2) endif else if tab_number == tabpagenr('

Then in my GVim, I map [ctrl+shift+left] to move left, [ctrl+shift+right] to move left


)
             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

云巢 2024-08-25 18:31:17

chris.ritsen 的解决方案在 vim v7.4 中不再为我工作,所以这里有一个更简单的替代方案:

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

chris.ritsen's solution stopped working for me in vim v7.4 so here's a simpler alternative:

" Move tabs left/right
nnoremap <silent> <s-left> :-tabmove<cr>
nnoremap <silent> <s-right> :+tabmove<cr>
找回味觉 2024-08-25 18:31:17

Ken Takata 编写了一个补丁来执行此操作 https://groups.google.com /forum/#!msg/vim_dev/LnZVZYls1yk/PHQl4WNDAgAJ 。一种选择是下载 vim 源代码,应用此补丁并编译。

Ken Takata wrote a patch to do this https://groups.google.com/forum/#!msg/vim_dev/LnZVZYls1yk/PHQl4WNDAgAJ . One option is to download vim source code, aply this patch and compile.

葬﹪忆之殇 2024-08-25 18:31:17

将选项卡向左/右移动

这不涉及使用鼠标,但它使用非常简单的 gvim 键盘映射:

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

现在您将能够移动当前选项卡:

  • 向左移动使用: Alt + [
  • 向右使用: Alt + ]

Move Tabs to the Left / Right

This doesn't involve using a mouse, but it uses very simple keymaps for gvim:

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

Now you'll be able to move the current tab:

  • To the left using: Alt + [
  • To the right using: Alt + ]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文