开发者

Skipping a window in VIM with Ctrl-W_W

开发者 https://www.devze.com 2023-01-21 05:31 出处:网络
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.

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 win开发者_如何学Cdows 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.


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消