0

For example, I'd like to map <leader>l to enter command-line mode with a command (AsyncRun followed by a space) partially typed in, so that I can continue to type to complete the command.

So typing <leader>l will enter command-line mode with the following command waiting for further input:

:AsyncRun

And then typing echo hello will complete the full command and pressing Enter will execute it:

:AsyncRun echo hello

Is there any way to create a mapping like this?

1

2 Answers 2

1

You can use the following normal mode mapping:

nnoremap <leader>l :AsyncRun<Space>

N.B. Instead of <Space>, you could just type a literal space character, but it's easier to see what the above is doing at a glance. If you wanted to start your rhs with a space, then using the <Space> notation is required. See :help map_space_in_rhs.

0

You can request input form the user using input(.

        :if input("Coffee or beer? ") == "beer"
        :  echo "Cheers!"
        :endif

This supports arbitrary completion (see :help input().

Alternatively, inputlist( will allow the user to select from a list of items, either by mouse or typing a number.

See also inputdialog( for a GUI alternative.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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