On command-line mode, Delete key erases next character, but if cursor is at end of line, it acts as Backspace, erasing previous character. Can I disabled that?

1 Answer 1


Try this:

:cnoremap <expr> <del> strlen(getcmdline()) == getcmdpos() - 1 ? '' : "\<del>"

This binds the delete key on the :-command line to running an expression and executing the keystrokes the expression returns. In this case I'm using a ternary operator to return nothing if the length is the same as the cursor position, and returning the delete key otherwise.

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.