Tab completion with a popup menu in vim works pretty well with the right configuration. http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
I have a small collection of code generator and code manipulating programs which I use in vim. The procedure is:
1. initiate visual mode
2. highlight text
3. :'<,'>!hashify
I would like to harness vim popup menu to offer a selection of actions.
The new procedure would be:
1. initiate visual mode
2. highlight text
3. <Tab> -- select transform option from menu
Is there a vimscript interface which could be used for this?
The insert mode completion popup can be used to insert a choice of text fragments. There are two ways to implement it, see :help complete-functions
and :help complete()
. If your code generator returns single-line (and not too long) text fragments to insert, you could invoke the generator via system(...)
and then feed the returned values to the completion function.
On the other hand, if the menu choices do not directly correspond to inserted text, but are tactical choices or actions, most plugins present a selection menu like this, styled like built-in menus (e.g. from :ilist
):
:echohl Title
:echo 'Code fragments:'
:echohl None
:echo '1. foo'
:echo '2. bar'
:let choice = nr2str(getchar())
:if choice == 1 ...
Then, insert the text corresponding to the choice via :normal! iText
, or setline()
.
As you appear to need the completion from visual mode, you can first capture the selected text by starting your mapping with y
.
This plugin allows to create popups like that for Vim:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With