Skip to content

Instantly share code, notes, and snippets.

@madx
Created January 23, 2013 09:33
Show Gist options
  • Select an option

  • Save madx/4603650 to your computer and use it in GitHub Desktop.

Select an option

Save madx/4603650 to your computer and use it in GitHub Desktop.
This is how I manage my windows in Vim. You may also be interested in dwm.vim (https://github.com/spolu/dwm.vim)
" Put this in .vim/bundle/master-window/plugin/ if you are using Pathogen
" Figure out a way to get this loaded if you aren't
if exists("master_window_loaded")
finish
endif
let master_window_loaded = 1
function! FocusMasterWindow()
exe "1wincmd w"
endfunction
function! SwapWithMasterWindow()
call MarkWindowSwap()
call FocusMasterWindow()
call DoWindowSwap()
endfunction
function! MarkWindowSwap()
let g:markedWinNum = winnr()
endfunction
function! DoWindowSwap()
let curNum = winnr()
let curBuf = bufnr( "%" )
exe g:markedWinNum . "wincmd w"
let markedBuf = bufnr( "%" )
exe 'hide buf' curBuf
exe curNum . "wincmd w"
exe 'hide buf' markedBuf
endfunction
nnoremap <silent> <leader>ww <C-W>w
nnoremap <silent> <leader>wW <C-W>W
nnoremap <silent> <leader>ws <C-W>s
nnoremap <silent> <leader>wv <C-W>v
nnoremap <silent> <leader>wq <C-W>q
nmap <silent> <leader>w<Space> :call FocusMasterWindow()<CR>
nmap <silent> <leader>w<CR> :call SwapWithMasterWindow()<CR>
nmap <silent> <leader>wm :call MarkWindowSwap()<CR>
nmap <silent> <leader>wx :call DoWindowSwap()<CR>
nmap <silent> <C-W>w <nop>
nmap <silent> <C-W>W <nop>
nmap <silent> <C-W>s <nop>
nmap <silent> <C-W>v <nop>
nmap <silent> <C-W>q <nop>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment