Skipping a window in VIM with Ctrl-W_W

感情迁移 提交于 2019-12-04 10:02:39

问题


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>


来源:https://stackoverflow.com/questions/3984544/skipping-a-window-in-vim-with-ctrl-w-w

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!