Skip to content

Instantly share code, notes, and snippets.

@tamago324
Last active September 12, 2019 10:15
Show Gist options
  • Select an option

  • Save tamago324/75d4c72051be9fee0df1b31837717a47 to your computer and use it in GitHub Desktop.

Select an option

Save tamago324/75d4c72051be9fee0df1b31837717a47 to your computer and use it in GitHub Desktop.
popup window の標準的な処理を書いてみる
let s:winid = 0
function! s:open_pop() abort
if s:winid != 0
call s:show_pop()
return
endif
let s:winid = popup_create('', {
\ 'pos': 'center',
\ 'minwidth': 40,
\ 'minheight': 10,
\ 'borderchars': ['-', '|', '-', '|', '+', '+', '+', '+'],
\ 'border': [1, 1, 1, 1],
\ 'padding': [1, 1, 1, 1],
\ })
endfunction
function! s:settext_pop(text) abort
call popup_settext(s:winid, a:text)
endfunction
function! s:close_pop() abort
call popup_close(s:winid)
let s:winid = 0
endfunction
function! s:hide_pop() abort
call popup_hide(s:winid)
endfunction
function! s:show_pop() abort
call popup_show(s:winid)
endfunction
function! s:split_bufnr() abort
" popup window に紐づく buffer number を取得し、編集する
exec 'sbuffer '.winbufnr(s:winid)
endfunction
command! -buffer SplitPopupBuf call <SID>split_bufnr()
command! -buffer OpenPop call <SID>open_pop()
command! -buffer ClosePop call <SID>close_pop()
command! -buffer HidePop call <SID>hide_pop()
command! -buffer ShowPop call <SID>show_pop()
command! -buffer -nargs=1 SetTextPop call <SID>settext_pop(<f-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment