Move adjacent tab to split?

前端 未结 2 1672
攒了一身酷
攒了一身酷 2021-02-02 06:51

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 r

相关标签:
2条回答
  • 2021-02-02 06:54

    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
    
    0 讨论(0)
  • 2021-02-02 07:06

    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>
    
    0 讨论(0)
提交回复
热议问题