Skip to content

Instantly share code, notes, and snippets.

@marcotrosi
Created July 12, 2017 04:46
Show Gist options
  • Save marcotrosi/45be104ba90215542d0b4d6ebc84a1d4 to your computer and use it in GitHub Desktop.
Save marcotrosi/45be104ba90215542d0b4d6ebc84a1d4 to your computer and use it in GitHub Desktop.
this is a draft for a Vim plugin to keep my plugins in the "same" window
if exists('loaded_panel')
finish
endif
let loaded_panel = 1
" TODO maybe move configuration to .vimrc
" TODO when a width of 0 is given -> ask panel for size; introduce min/max width
let s:panels_config = { 'files':{'run':'Files', 'width':60},
\ 'buffers':{'run':'Buffers', 'width':20},
\ 'tags':{'run':'Tags', 'width':30},
\ 'sessions':{'run':'Sessions', 'width':15},
\ 'misspellings':{'run':'Misspellings', 'width':25}}
" init value in case PanelToggle is called first
let s:panel = "files"
function! Files()
let l:content="files panel"
put! =l:content
endfunction
function! Buffers()
let l:content="buffers panel"
put! =l:content
endfunction
function! Tags()
let l:content="tags panel"
put! =l:content
endfunction
function! Sessions()
let l:content="sessions panel"
put! =l:content
endfunction
function! Misspellings()
let l:content="misspellings panel"
put! =l:content
endfunction
function! PanelToggle()
let bufnr = bufwinnr("__PANEL__")
if bufnr == -1
silent! vsplit __PANEL__
setlocal buftype=nofile
setlocal bufhidden=wipe
setlocal noswapfile
setlocal nowrap
setlocal nobuflisted
setlocal nonumber
setlocal nospell
setlocal statusline=
exec 'vertical resize '.s:panels_config[s:panel]['width']
exec 'call '.s:panels_config[s:panel]['run'].'()'
nnoremap <buffer> <silent> q :bwipeout!<CR>
setlocal nomodifiable
else
bwipeout! __PANEL__
endif
endfunction
function! Panel(tool)
let bufnr = bufwinnr("__PANEL__")
if bufnr == -1
silent! vsplit __PANEL__
setlocal buftype=nofile
setlocal bufhidden=wipe
setlocal noswapfile
setlocal nowrap
setlocal nobuflisted
setlocal nonumber
setlocal nospell
setlocal statusline=
let s:panel = a:tool
exec 'vertical resize '.s:panels_config[s:panel]['width']
exec 'call '.s:panels_config[s:panel]['run'].'()'
nnoremap <buffer> <silent> q :bwipeout!<CR>
setlocal nomodifiable
else
if s:panel != a:tool
let s:panel = a:tool
setlocal modifiable
%d
exec 'vertical resize '.s:panels_config[s:panel]['width']
exec 'call '.s:panels_config[s:panel]['run'].'()'
nnoremap <buffer> <silent> q :bwipeout!<CR>
setlocal nomodifiable
else
if bufname("%") == "__PANEL__"
bwipeout! __PANEL__
else
execute bufnr . 'wincmd w'
" TODO remove resize command; find out why Vim is resizing the window on its own
exec 'vertical resize '.s:panels_config[s:panel]['width']
endif
endif
endif
endfunction
" TODO create <SID>commands and make functions local to script; remove mappings
nnoremap <F1> :call PanelToggle()<CR>
nnoremap <F2> :call Panel('files')<CR>
nnoremap <F3> :call Panel('buffers')<CR>
nnoremap <F4> :call Panel('tags')<CR>
nnoremap <F5> :call Panel('sessions')<CR>
nnoremap <F6> :call Panel('misspellings')<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment