1

Is it possible to suppress the output of a register? For example, I am using getchar() to 'consume' a character, but I don't need it to return anything. I suppose I could add in a hackish ternary operator to do this, such as:

=getchar()?'':''

But I was wondering if there was a cleaner or better way to do this?

2
  • "cleaner" is subjective, but getchar()[-1] is shorter.
    – user938271
    Commented Jun 27, 2020 at 19:59
  • @user938271 thanks. Do you want to post an answer and show how that would work? Does the -1 work differently than for example it does in python?
    – David542
    Commented Jun 27, 2020 at 20:00

1 Answer 1

1

"cleaner" is subjective, but getchar()[-1] is shorter.

From :h expr-[]:

A negative index always results in an empty string (reason: backward compatibility).

1
  • interesting...thanks for the explanation.
    – David542
    Commented Jun 27, 2020 at 20:07

Your Answer

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

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