1

Let me give a bit of context to the question:

  • I need to show a 'prompt' in the preview window when the user makes a selection of an item in a popup window, which is similar to the way the tern-for-vim completion plugin does in Javascript files, but I'm intending to make it work for any file.

  • I'd rather have the preview window opened beforehand (either by the user, or the script, currently it doesn't matter), since I find it hard to position it, when it's being opened (I prefer the topmost position full width, and it seems there is no command like e.g. <C-W>L, which moves the window to the right, that is if one has the terminal window split vertically, the preview window will have only half of the terminal's width, like in the picture below).

half-width preview window

  • So when the user selects an item in the list, the preview window is automatically filled with the prompt

Currently I find the :pedit command the best approach to this, since it automatically selects the preview window, if one exists. But the issue with it is that it seems to accept only a filename, and I'd rather not have such a file in the user's system, because of (many writes to the file, where to place it [it shouldn't be created in any pwd] and possibly other reasons).

Another approach can be to loop thru all windows, find the preview one, and edit it with some normal commands.

Could anyone advise something on this, please? Thank you

  • If youre showing a prompt, there is a buftype called prompt for that – D. Ben Knoble Jun 15 at 11:17
  • @D.BenKnoble no, I guess this is different. It's an more like autocompletion with a cheat sheet. When the user invokes it, it shows possible options to complete and a cheat sheet for the currently selected option – user907860 Jun 15 at 22:01
0

I found, that despite that the pedit command accepts a file name, it doesn't have to be an existing file. So with pedit some-dummy-name.txt one can use the currently opened preview window automatically and its buffer will be replaced with 'dummy-name.txt', so that the script can safely change it.

Then it's necessary to populate it with lines of the "prompt" (a better name might be "cheat sheet") with deletebuflines() & addbuflines().

On Vim exit the file won't be saved and no warning will be given.

Currently, I find this the optimal approach

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.