Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Have you ever seen vim's popup menu?
Simone Gentili
Simone Gentili

Posted on

     

Have you ever seen vim's popup menu?

popup menu, ...

Is a Vim function that displays a menu in a popup window. Yes, .. Vim has popup windows. The menu can contain a list of items. In the following example I've added just two: open vimrc file and replace current word. I this example, ... You'll see the code to select an item by clicking on it.

The popup_menu() function takes a list of items as an argument, and it returns the index of the selected item. Somewere inthe documentation I sow index starts from 0, .. but not for me: the first item in the list is 1, the index of the second item is 2, and so on.

The popup_menu() function also supports various options that allow you to customize the appearance and behavior of the popup menu. For example, you can specify the title of the menu, the callback function that is called when an item is selected, and the highlight style of the menu.

In this example the menu is"What do you want?". I've also added a this to open the popup menu:

nnoremap <leader><leader> :call Funzione()<CR>
Enter fullscreen modeExit fullscreen mode

So, ... it si very very simple to open popup. Oh, .. And you can simply ESC to close it without a selection.

" menu stufffunction! SensorarioTools(id, result)    if a:result == 1        :e ~/.vimrc    endif    if a:result == 2        set nopaste        let user_input = input('Enter a word:')        let current_word = expand('<cword>')        execute '%s/'.current_word.'/'.user_input.'/g'    endifendfuncfunc! Funzione()  call popup_menu([    \ 'open ~/.vimrc',    \ 'replace current word',    \ ], #{    \ title: "What do you want?",    \ callback: 'SensorarioTools',    \ line: 25,    \ col: 60,    \ highlight: 'Question',    \ border: [],    \ close: 'click',    \ padding: [1,20,1,1],    \ })endfuncnnoremap <leader><leader> :call Funzione()<CR>
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Father
  • Work
    Software Developer @ radical storage
  • Joined

More fromSimone Gentili

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp