Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip navigation to a Vim split

Tags:

vim

I have recently added the excellent fholgado/minibufexpl.vim plugin to got a readily available display of all the existing buffers.

My problem now, though, is that I heavily rely on CTRL+W W/H/J/K/L to switch between splits and I keep missing that I'm in the plugin's split.

Is it possible to write some Vim code which would skip or disable navigation to a certain split?

like image 612
Filip Dupanović Avatar asked Apr 26 '26 05:04

Filip Dupanović


1 Answers

Do the following code do what you're expecting? It remaps some window focus commands (<C-W>l/h/j/k/w), so that it skips the BDE window, if it's opened.

" Remapping the following <ctrl-w>... commands:
for wincmd in ['l', 'h', 'j', 'k', 'w']
    exe 'noremap <silent> <c-w>'.wincmd.' :WincmdSkipMBE '.wincmd.'<cr>'
endfor

command! -nargs=1 WincmdSkipMBE call WincmdSkipMBE(<f-args>)

function! WincmdSkipMBE(cmd)
    let l:first = winnr()
    while 1
        let l:last = winnr()
        exe 'wincmd '.a:cmd
        let l:new = winnr()
        if l:last == l:new | exe l:first.'wincmd w' | break
        elseif bufname('%') != '-MiniBufExplorer-' | break
        endif
    endw
endf

I'm not totally sure of what you're asking. When you say:

I heavily rely on CTRL+W W/H/J/K/L to switch between splits

, do you rather mean CTRL-W w/h/j/k/l (lowercase) ?

like image 53
yolenoyer Avatar answered Apr 28 '26 04:04

yolenoyer