Move adjacent tab to split?

て烟熏妆下的殇ゞ 提交于 2019-12-20 10:17:45

问题


Is there an easy way to move an adjacent tab in Vim to current window as a split?

While looking around I reached a mailing list discussion where someone said it's the reverse of the operation Ctrl+W,T without providing the solution.


回答1:


I am providing two solutions, the first one I checked myself and I can guarantee it's working. The second, I am trying soon.
First solution: install this plugin http://www.vim.org/scripts/script.php?script_id=1961 by simply creating the folder ~/.vim/plugin and downloading the file Tabmerge.vim into the folder. Then, when you have two tabs and you type

:Tabmerge

you will merge the two tabs into one, splitted horizontally and top aligned. Check out the link to find a complete usage guide.

Alternatively, check out this page http://vim.wikia.com/wiki/Move_current_window_between_tabs for the code of two functions to move current window between tabs. Here the functions (which I didn't try yet):

function MoveToPrevTab()
  "there is only one window
  if tabpagenr('$') == 1 && winnr('$') == 1
    return
  endif
  "preparing new window
  let l:tab_nr = tabpagenr('$')
  let l:cur_buf = bufnr('%')
  if tabpagenr() != 1
    close!
    if l:tab_nr == tabpagenr('$')
      tabprev
    endif
    sp
  else
    close!
    exe "0tabnew"
  endif
  "opening current buffer in new window
  exe "b".l:cur_buf
endfunc

and

function MoveToNextTab()
  "there is only one window
  if tabpagenr('$') == 1 && winnr('$') == 1
    return
  endif
  "preparing new window
  let l:tab_nr = tabpagenr('$')
  let l:cur_buf = bufnr('%')
  if tabpagenr() < tab_nr
    close!
    if l:tab_nr == tabpagenr('$')
      tabnext
    endif
    sp
  else
    close!
    tabnew
  endif
  "opening current buffer in new window
  exe "b".l:cur_buf
endfunc



回答2:


The problem with your problem is that a tab is not tied to a specific buffer. You can have 10 windows with as many buffers in a tab so "moving a tab into a split" doesn't make much sense.

What makes more sense is "show buffer x into a split" which can be done with

:sb <name_of_buffer>


来源:https://stackoverflow.com/questions/14688536/move-adjacent-tab-to-split

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