2

I've used the information in this answer previously, but recently encountered a minimal installation with only vi. I edited the .vimrc in the user's home folder (~/.vimrc), but when typing jj, the literal text <esc> was entered within insert mode.

How does one do an inoremap for the escape key in vi?

1 Answer 1

3

The key syntax with brackets, such as <Esc>, is specific to Vim.

In plain vi, you need to enter an actual ESC character in your mapping.

You can do so by pressing Ctrl+V, followed by ESC, which will insert an actual ESC and will be displayed as ^[.

The command will look like:

:inoremap jj ^[

But note that the ^[ is a single ESC character and is entered with the sequence described above.

2
  • Thank you - I am familiar with escape sequences, but didn't realize this was required for vi. Will this also work in vim? I.e.: Can I use this for my .vimrc and whatever the analog file is for vi? Commented Oct 16, 2019 at 4:29
  • Yes, literal escape sequences will work for Vim as well. In fact, they'll work in Vim even in compatible mode. The vi init file is typically ~/.exrc.
    – filbranden
    Commented Oct 16, 2019 at 4:33

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.