Custom popup menu in VIM

Finishing a tab using the popup menu in vim works just fine with the correct configuration. http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE

I have a small collection of code generators and code management programs that I use in vim. The procedure is as follows:

1. initiate visual mode 2. highlight text 3. :'<,'>!hashify 

I would like to use the vim popup menu to suggest a few actions.

New procedure:

 1. initiate visual mode 2. highlight text 3. <Tab> -- select transform option from menu 

Is there a vimscript interface that could be used for this?

+7
source share
2 answers

You can use the paste mode completion popup window to insert a selection of text fragments. There are two ways to implement it, see :help complete-functions and :help complete() . If the code generator returns single (and not too long) text fragments to insert, you can call the generator through system(...) , and then pass the return values ​​to the completion function.

On the other hand, if the menu selection does not correspond directly to the inserted text, but is a tactical choice or actions, most plugins are a selection menu like this in a style similar to the built-in menu (for example, from :ilist ):

 :echohl Title :echo 'Code fragments:' :echohl None :echo '1. foo' :echo '2. bar' :let choice = nr2str(getchar()) :if choice == 1 ... 

Then paste the text matching the selection with :normal! iText :normal! iText or setline() .

As it seems to you that you want to render in visualization mode, you can first capture the selected text by starting your mapping with y .

+2
source

This plugin allows you to create pop-ups like this one for Vim:

enter image description here

+3
source

All Articles