1

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?

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.

  • 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? – user3.1415927 Oct 16 '19 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 Oct 16 '19 at 4:33

Your Answer

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

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