有没有办法在VIM中实现窗口导航

有没有办法在VIM中实现窗口导航,vim,macvim,nerdtree,Vim,Macvim,Nerdtree,我希望这样,从最右边的窗口键入Ctrl-Wk可以聚焦VIM中最左边的窗口。显然,这将是方便的工作在各个方向 我的主要动机是与NERDTree一起使用。我通常有以下设置: |----------|----------|-----------| | | | | | NERDTree | File1 | File2 | | | | | | |---------

我希望这样,从最右边的窗口键入Ctrl-Wk可以聚焦VIM中最左边的窗口。显然,这将是方便的工作在各个方向

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

|----------|----------|-----------|
|          |          |           |
| NERDTree |   File1  |   File2   |
|          |          |           |
|          |----------|-----------|
|          |          |           |
|          |   File3  |   File4   |
|          |          |           |
|----------|----------|-----------|
如果我想在与
File4
相同的窗口中打开一个新文件,我当前必须键入2Ctrl Wj,使用Ctrl-Wk可以获得相同的结果

谢谢。

可以使用

<C-w>w
w

W
分别向右/向下和向左/向上循环浏览所有窗口。这两个命令都是环绕的,因此
w
将在某个点的左上角结束,而
w
将在某个点的右下角结束

请参见
:h窗口移动光标


或者只需使用直接进入目标窗口的
b

您必须使用自己的映射覆盖
$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>
”
“换行窗口移动光标
"
函数!s:GotoNextWindow(方向、计数)
设l:prevWinNr=winnr()
执行a:计数。'wincmd'a:方向
返回winnr()!=l:prevWinNr
端功能
函数!s:带包裹的跳线(方向,相反)
如果!s:GotoNextWindow(a:方向,v:计数1)
拨打s:GotoNextWindow(a:999)
恩迪夫
端功能
nnoremap h:调用JumpWithWrap('h','l')
nnoremap j:调用JumpWithWrap('j','k')
nnoremap k:调用JumpWithWrap('k','j')
nnoremap l:调用JumpWithWrap('l','h')
nnoremap:调用JumpWithWrap('h','l')
nnoremap:调用JumpWithWrap('j','k')
nnoremap:调用JumpWithWrap('k','j')
nnoremap:调用JumpWithWrap('l','h')

您必须编写一些代码才能完成此任务,并将其映射到所需的组合键。检查
:h窗口移动光标
;移动命令列在那里。这是我的想法。不幸的是,我还不太熟悉vim脚本:)废话,出于某种原因,这跳过了netrw
"
" 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>