0

I have a function which calls another function that reads user input from input().

function! fun1()
  call fun2()
endfunction

function! fun2()
  let temp = input("Please input:")
endfunction

What I want is when typing in the command area of vim with Please input: xxx, if I press <esc>, fun1 will be stopped/ not executed.

How is it possible to do this?

Trying to catch the <esc> key with:

try
  let temp = input("Input: ") " show what is already there
catch "normal! <esc>"
  echo "esc catched"
finally
  echo "\n".temp
endtry

does not seems to work.

  • Wouldn't it be easier to simply use <C-c>? (At least I believe that is what it was made for) – statox May 14 at 7:58
  • Well, but <esc> is also a normal behaviour when you enter sth and don't want to do it anymore. In general the key shouldn't matter, my question is how to catch it. – X.Arthur May 14 at 9:34
  • Depending on your usecase, inputdialog() might be an option. – Ralf May 14 at 9:48
  • @Ralf that func is listed in the deprecated list in neovim, and suggested to use input. I think we should focus on the problem. – X.Arthur May 14 at 10:24

Your Answer

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

Browse other questions tagged or ask your own question.