有没有办法让窗口导航环绕在VIM中

Wes*_*Wes 8 vim macvim nerdtree

我希望它能Ctrl-Wk从最右边的窗口输入,将最左边的窗口聚焦在VIM中.显然,在各个方向上工作都很方便.

我的主要动机是与NERDTree一起使用.我通常有以下设置:

|----------|----------|-----------|
|          |          |           |
| NERDTree |   File1  |   File2   |
|          |          |           |
|          |----------|-----------|
|          |          |           |
|          |   File3  |   File4   |
|          |          |           |
|----------|----------|-----------|
Run Code Online (Sandbox Code Playgroud)

如果我想在File4我目前要输入的同一个窗口中打开一个新文件,那么用2Ctrl-Wj它来获得相同的结果会很不错Ctrl-Wk.

谢谢.

Ing*_*kat 5

您必须$HOME/.vimrc使用包含此额外逻辑的自己的映射覆盖您的默认命令.当正常移动不再改变窗口时(即我们已经在边界处),跳转到另一侧.

"
" Wrap window-move-cursor
"
function! s:GotoNextWindow( direction, count )
  let l:prevWinNr = winnr()
  execute a:count . 'wincmd' a:direction
  return winnr() != l:prevWinNr
endfunction

function! s:JumpWithWrap( direction, opposite )
  if ! s:GotoNextWindow(a:direction, v:count1)
    call s:GotoNextWindow(a:opposite, 999)
  endif
endfunction

nnoremap <silent> <C-w>h :<C-u>call <SID>JumpWithWrap('h', 'l')<CR>
nnoremap <silent> <C-w>j :<C-u>call <SID>JumpWithWrap('j', 'k')<CR>
nnoremap <silent> <C-w>k :<C-u>call <SID>JumpWithWrap('k', 'j')<CR>
nnoremap <silent> <C-w>l :<C-u>call <SID>JumpWithWrap('l', 'h')<CR>
nnoremap <silent> <C-w><Left> :<C-u>call <SID>JumpWithWrap('h', 'l')<CR>
nnoremap <silent> <C-w><Down> :<C-u>call <SID>JumpWithWrap('j', 'k')<CR>
nnoremap <silent> <C-w><Up> :<C-u>call <SID>JumpWithWrap('k', 'j')<CR>
nnoremap <silent> <C-w><Right> :<C-u>call <SID>JumpWithWrap('l', 'h')<CR>
Run Code Online (Sandbox Code Playgroud)


rom*_*inl 4

一个可以用

<C-w>w
Run Code Online (Sandbox Code Playgroud)

<C-w>W
Run Code Online (Sandbox Code Playgroud)

分别向右/向下和向左/向上循环浏览所有窗口。这两个命令都会环绕,因此<C-w>w有时会在左上角结束,<C-w>W有时会在右下角结束。

:h window-move-cursor

或者简单地使用<C-w>b它直接进入您的目标窗口。