通过所有打开的分割旋转 vim 缓冲区

问题描述 投票:0回答:1

如何通过所有拆分轮换所有当前可见的打开缓冲区? (旋转的确切方向对我来说并不是至关重要,尽管有一些选择会很好。)我正在寻找像 Ctrl-Wr 这样的东西,它适用于严格的水平和垂直分割,但不旋转“通过”两者。想象一下一个垂直分割和一个或两个分割被水平分割。

例如,给定:

----------------------------
  buffer a   |    buffer b
----------------------------
  buffer d   |    buffer c
----------------------------


The command should rotate the buffers to the following split windows(e.g.):

----------------------------
buffer d     |   buffer a
----------------------------
buffer c     |   buffer b
----------------------------

我认为一般来说类似的事情应该很简单。我理解在这种情况下确定顺时针含义的复杂性,但我对任何定义都非常满意。想象一下,缓冲区全部存储在堆栈中(它们可能是这样),我非常乐意将顶部的缓冲区从堆栈中弹出并将其推到底部。

通过垂直分割旋转的命令也可以工作:

----------------------------
  buffer a   |    buffer b
----------------------------
  buffer d   |    buffer c
----------------------------

to:

----------------------------
  buffer b   |    buffer a
----------------------------
  buffer c   |    buffer d
----------------------------


即使在存在水平分割的情况下跨垂直分割移动缓冲区的任何方法也会有所帮助。我尝试了所有我能找到的 Ctrl W 选项,进行了广泛的搜索,并向法学硕士询问。 (我还没有查看源代码,也没有查看与直接操作缓冲区相关的选项。)

vim split buffer
1个回答
0
投票

添加以下内容 _vimrc 创建该功能并将其绑定到 Ctrl-w Ctrl-a

function! RotateBuffers()
    " Get the total number of windows
    let totalWindows = winnr('$')

    " If there's only one window, no rotation needed
    if totalWindows == 1
        return
    endif

    " Get the buffer number of the first window
    let firstBuf = winbufnr(1)

    " Iterate over windows starting from the second window
    for winNum in range(2, totalWindows)
        " Switch to the window
        execute winNum . 'wincmd w'

        " Get the buffer number for the current window
        let bufNum = winbufnr(winNum)

        " Move to the previous window
        execute (winNum - 1) . 'wincmd w'

        " Set the buffer of the previous window to the current window's buffer
        execute 'buffer ' . bufNum
    endfor

    " Set the buffer of the last window to the buffer of the first window
    execute totalWindows . 'wincmd w'
    execute 'buffer ' . firstBuf
endfunction

" Call the function
call RotateBuffers()


nnoremap <C-W><C-A> :call RotateBuffers()<CR>
© www.soinside.com 2019 - 2024. All rights reserved.