1

Is there any way to have the confirm function place the choices on the same line as the msg prompt?

confirm("Yes no question", "&Yes\n&No", 2)

Instead of

Yes no question
(Y)es, [N]o: 

it would save a message area scroll if it was

Yes no question (Y)es, [N]o:

Docs mention adding \n to msg for newlines in the prompt, but looking for a way to suppress the newline between msg and choices.

2
  • I think you can't change anything in inbuilt function like confirm. You nay try a echo command along with a getchar like command.
    – SibiCoder
    Sep 4 '16 at 5:34
  • Thanks for the hint @SibiCoder. If you post an answer of No, can't ... I'll accept it to close the question. Sep 4 '16 at 9:14
3

Unfortunately you can't; this format is "hardcoded" (in msg_show_console_dialog()).

But you can re-create a function which mostly behaves the same with getchar():

fun! Confirm(msg)
    echo a:msg . ' '
    let l:answer = nr2char(getchar())

    if l:answer ==? 'y'
        return 1
    elseif l:answer ==? 'n'
        return 0
    else
        echo 'Please enter "y" or "n"'
        return Confirm(a:msg)
    endif
endfun

This doesn't implement all the features that confirm() has, but it should show the basic idea.

2
  • And the reason this came up @Carpetsmoker, was to tweak your Undo across persistence warning. I haven't tried the plugin, but took the code snippet. Changed to prompt before proceeding instead of an after the fact warning. (I also tweaked it so u would work with unnamed buffers, I use Vim for all kinds of experimental edits and stdin viewing). So, thanks for that. vi.stackexchange.com/a/3151/9087 Sep 4 '16 at 18:02
  • @BrianTiffin You can already set g:undofile_warn_prevent = 1 and you'll have to press u twice − having a more explicit confirm sounds like a nice feature to add. Would also like to hear about your fix for unnamed buffers by the way (that's probably best done outside these comments there btw, you can mail me at martin@arp242.net). Sep 4 '16 at 18:08
1

You can do this

confirm('',"Yes No Question? (&Yes\n&No)",1) == 1 ? "do somthing" : "do something else"

source

2
  • The trick with putting the message in the answers is nice! I think that deserves more mention in the answer; the rest is incidental and not really part of the question.
    – D. Ben Knoble
    Sep 21 at 21:29
  • @D.BenKnoble I don't really know what to explain. If you have something to add, by all means, edit the answer.
    – Ali
    Sep 22 at 12:10

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.