I'm planning to write a simple pop-up for myself and I found a nice beginning point for this in this question, but I want to make the code compatible with nvim as well. I can't seem to find a similar "intro" for nvim and I'm also hoping that there's code out there that abstracts this away for me (i.e handling vim and nvim). Could someone point me to resources?
-
I was looking for something like the code you describe and found this: vim-lsp FloatingWindow.vim. Haven't looked too closely but my initial impression is that it could be useful.– B LayerJan 12, 2022 at 13:24
-
1I was able to add popup support to ALE, so this file has both neovim and vim popup code in it.– D. Ben Knoble ♦Jan 12, 2022 at 14:47
-
@D.BenKnoble Thanks! that looks like something my meager vimscript skills can utilize :)– fbenceJan 12, 2022 at 14:52
-
1@D.BenKnoble I happen to have ALE installed, so just tried it out, works perfectly out of the box thanks! If you don't mind I am going to copy it as-is.– fbenceJan 13, 2022 at 18:52
-
1@fbence I would take a look at ALE’s license and make sure you follow any conditions there.– D. Ben Knoble ♦Jan 13, 2022 at 19:10
1 Answer
Beware that Vim popup is "modal". It can have a border and other stuff while omitting normal editing capabilities. That makes it to behave much like "a popup menu" and not a regular window. While in Neovim it's "normal floating window" that can edit the text but has no builtin support for "menu mode". So there's a big difference in design.
I'm planning to write a simple pop-up for myself
I did that for my personal config some time ago. The trick is to create two floatwins - one for border and another one for displaying "menu items". Then set :h 'cursorline'
, :h 'nomodifiable'
, add a few buffer-local keymaps and all that usual stuff that plugins do to customize "special buffers".
The code is right here. It's working, but it's neither clean nor complete. So I consider rewriting it from scratch... some day. Well, you were warned.
The API deliberately follows one of Vim, except for some unimplemented features.
I also added sort of "general picking capability" utilizing popups. The code is mostly here and here. I've explained it a little in this answer.