Skipping a window in VIM with Ctrl-W_W

2020-05-29 06:34发布

问题:

When I have several windows open in VIM, I'd like to always skip one of them (the one containing my project using Aric Blumer's Project plugin), whenever I press Ctrl-W_W.

In other words I'd like to cycle through my document windows as if the Project window wasn't one of them. When I actually do want to go into the project window, I'll use the mapping I created especially for this purpose.

Is there a way to mark a window so that it's skipped by Ctrl-W_W or would I need a script? I'm loving Vim but am still in the steep part of the learning curve.

回答1:

You would have to write a function (it's easier to maintain) that cycles to the next window, and skip it if it matches the name of the windows you don't want to go into.

Something like:

function! s:NextWindowBut(skip,dir)
  let w0 = winnr()
  let nok = 1
  while nok
    " exe "normal! \<c-W>w"
    " or better
    exe 'wincmd '.a:dir
    let w = winnr()
    let n = bufname('%')
    let nok = (n=~a:skip) && (w != w0)
    " echo "skip(".n."):".(n=~a:skip)." w!=w0:".(w != w0)." --> ".nok
  endwhile
  if w == w0
    echomsg "No other acceptable window"
  endif
endfunction

nnoremap <silent> <C-W>w :call <sid>NextWindowBut('thepattern','w')<cr>
nnoremap <silent> <C-W>W :call <sid>NextWindowBut('thepattern','W')<cr>


标签: macvim vim