vim-plug
Plug 'kamykn/popup-menu.nvim'
NeoBundle
NeoBundle 'kamykn/popup-menu.nvim'
" This is a sample callback function
function! s:callback(selected) abort
echo a:selected
endfunction
let list = ['aaa', 'bbb', 'ccc', 'ddd', 'eee']
call popup_menu#open(list, {selected -> s:my_callback(selected)})
It can use 3rd argument as same settings as nvim_open_win().
call popup_menu#open(
\ list,
\ {selected -> s:my_callback(selected)},
\ {
\ 'relative': 'editor',
\ 'width': 30,
\ 'height': 7,
\ 'col': 5,
\ 'row': 5
\ })
" list for popup menu.
let list = [apple, banana, orange]
if exists('*popup_menu')
" Vim
let callback_fn = {win_id, index -> s:my_callback_idx(index)}
call popup_menu(list, #{
\ callback: callback_fn,
\ ...
\ })
elseif has('nvim') && exists('g:loaded_popup_menu_plugin')
" Neovim
" g:loaded_popup_menu_plugin is defined by popup-menu.nvim.
let callback_fn = {selected_str -> s:my_callback_str(selected_str)}
call popup_menu#open(list, callback_fn)
else
" Old vim/neovim
let index = inputlist(...)
call s:my_callback_idx(index)
endif
The style is same as PMenu
and PMenuSel
.
However, only ctermbg
and ctermfg
are used.
" sample settings
hi Pmenu ctermfg=254 ctermbg=237 cterm=NONE guifg=#e1e1e1 guibg=#383838 gui=NONE
hi PmenuSel ctermfg=135 ctermbg=239 cterm=NONE guifg=#b26eff guibg=#4e4e4e gui=NONE