There are two primary ways to prompt the user for input. You can either use confirm to display a multiple choice dialog (such as yes/no/cancel), or input to process a more complex input.

The confirm function prompts the user with a dialog and a multiple answers a user can select from. Let's try a simple example:

let answer = confirm('Is cat your favorite animal?', "&yes\n&no")echo answer

If you execute the script, you'll get the following prompt:

Hitting y or n will select an option. Let's hit y:

The result of this is 1. Now, what if ...

Get Mastering Vim now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.