Vim imap jk <Esc> not working
Asked Answered
H

3

5

In my vimrc, I've remapped jk to escape using imap.

The problem emerges when I use jk; it doesn't escape, it only echoes out <Esc>.

Here's the entry in quiestion: imap jk <Esc>

It's also a good point to make that I'm also using vim-X11 in fedora.

Hypnotherapy answered 4/12, 2012 at 14:3 Comment(3)
Could you show us the entry in your vimrc?Fear
:imap jk <Esc> works for me...Tortious
It's possible you have another mapping interfering. Try inoremmap jk <esc>Inchoate
G
5

It looks like your 'cpoptions' settings contains <; then, special key codes like <Esc> are not recognized.

Find out where this got set via

:verbose set cpo?

or re-write the mapping to use a literal Escape character; enter it via Ctrl + V Esc; it should appear as ^[ in the buffer.


PS: Though not related, you should usually use :inoremap unless remapping is required.

Glimmer answered 4/12, 2012 at 14:19 Comment(5)
Thanks, the Ctrl + V thing worked ok! The set cpo? returned a menu file, though. Which line am I looking to edit in it to remove this problem?Hypnotherapy
Oh, cpo is saved and restored in many scripts, so it's a challenge. Binary search (i.e. disabling half of your scripts) may work, but maybe it's easier to just put :set cpo-=< above your mapping definition.Glimmer
You, sir, are the freaking man! That worked perfectly which now means that <Esc> works just fine. Thanks for everything and happy solstice.Hypnotherapy
@JohnnyMcKenzie There is a way to force special meaning of <Esc> regardless of the value of 'cpoptions': imap <special> jk <Esc>.Disinter
@Disinter Thanks, I'll have to remember that one!Hypnotherapy
K
3

For those who are here because of the title, the jk mapping will also not work when :set paste is enabled.

Kellby answered 16/2, 2019 at 2:43 Comment(1)
Solved my problemParesthesia
L
0

Make sure set nocompatible is run before setting any mappings. I moved that line to the beginning of my vimrc and it worked.

I now changed it to the following so that Vrapper (Vim for Eclipse) works:

if v:true
  set nocompatible
endif
Loseff answered 21/6 at 19:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.