0

I'v remapped esc key by double jj for insert mode and command line mode.

When I using it in command line mode it removes the word where the cursor is highlighted

cnoremap jj <esc>
nnoremap rr :s/\<<C-r><C-w>\>/ 

The example above shows that rr key for normal mode is highlight the current words and after user input the word and press the enter key, the highlighted words will be replaced. However, after I entered rr in normal mode and want to cancel the replace action by press jj, it removes the word under the cursor, why is that? and how can I solve this

1
  • Tangent: maybe use * for your rr command, e.g. nnoremap rr *``:s// Commented Mar 20, 2019 at 15:56

1 Answer 1

2

That is expected behaviour. See :h c_ESC

In macros or when 'x' present in 'cpoptions', start entered command.

In the vim documentation, when mentioning macros, this also applies to mappings and abbreviations (basically whenever the input has not literally been typed).

So if you want to abort a command in command line mode, use CTRL-C instead.

1
  • Short! Clean! Correct! Precise! and Thanks
    – SLN
    Commented Mar 20, 2019 at 15:34

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.