92

I've been using Vim for several months now via my web host (they allow putty access). All of a sudden, the escape key has become unresponsive. I cannot exist insert or any other mode by simply hitting escape. I have to hit F1 which brings up the help in vim and kicks me into command mode.

I'm most certain that my escape key on my keyboard is functioning fine since all of my windows shortcuts that use the escape key operate normally.

I know this is a ridiculous question and I'm certain there's a lot more to look into regarding a solution. What I really need is a solid lead as to where to start looking.

Things that might help:

  1. I'm using vim via putty
  2. I'm logging in using jailshell
  3. I'm not root
Levi Hackwith
  • 973
  • 1
  • 7
  • 9
  • what are your terminal settings? ie what exactly is the TERM environment variable set to (in the remote shell)? – quack quixote Apr 11 '10 at 21:28
  • $TERM is set to 'xterm' – Levi Hackwith Apr 11 '10 at 21:33
  • 1
    Does `Ctrl-[` work? What do you get if you press `Ctrl-v` then escape? It should show as `^[`. – Dennis Williamson Apr 11 '10 at 21:35
  • The Ctrl-[ worked. Rock on! This saves me a lot of frustration. Is there any chance you can explain why `esc` no longer works? Also, please post your comment as an answer so I can accept it. – Levi Hackwith Apr 11 '10 at 21:42
  • My first thought when reading this: "Oh he broke his 'Get me the heck out of here' button" – Daniel Nov 10 '16 at 17:41
  • this just happened to me after a fresh install of gvim: turns out I was in gvim-easy … which is not so easy if you expect it to behave like vim. – ricardo Jul 03 '18 at 13:04
  • Today I was stuck in insert mode then I realized that mistakenly configured a shortcut on my konsole profile for ESC key... – sametcodes Aug 03 '19 at 16:00
  • This sometimes happens to me: accidentally freezing Vim, in a xfce4-terminal (it's actually the terminal that is frozen). Various xon-xoff solutions (Ctrl-Q ...) had no effect. Although no keyboard shortcut was evident, I noticed that from the terminal menu that the terminal had become set to "Read-Only." Unchecking that restored terminal responsiveness. – Victoria Stuart Sep 29 '20 at 21:37

6 Answers6

224

I had mistakenly hit Ctrl + s, and got stuck in the insert mode. To get out of it use Ctrl + q.

soandos
  • 24,206
  • 28
  • 102
  • 134
bhaskar
  • 2,241
  • 2
  • 13
  • 2
  • 11
    That's not insert mode that's [`XOFF`](http://en.wikipedia.org/wiki/Software_flow_control). You can disable software flow control by doing `stty -ixon` (add it to your `~/.bashrc`). Then that keystroke will be available to be bound to something else. By default in Bash it's bound to `forward-search-history` (the opposite of Ctrl-r). Ctrl-q (Bash `quoted-insert`) will also be available. – Dennis Williamson Jul 02 '12 at 14:18
  • @DennisWilliamson Wouldn't `.bash_profile` be a better place? There's no need to turn it off in non-interactive shell, is it? – Piotr Dobrogost Mar 04 '14 at 22:14
  • 1
    @PiotrDobrogost: ["When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists."](https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html#Bash-Startup-Files) `.bash_profile` is only executed when Bash is a login shell. "So, typically, your ~/.bash_profile contains the line `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi`" – Dennis Williamson Mar 04 '14 at 22:22
  • @DennisWilliamson You are right. What I meant to say is that there's probably sense to disable software flow control only in interactive shells. If this is true then subsequently it would make sense to find a way to tell if a shell is interactive and disable software flow control only in this case. – Piotr Dobrogost Mar 05 '14 at 20:01
  • @PiotrDobrogost: See [my answer](http://serverfault.com/a/146747/1293) to "How can I check in bash if a shell is running in interactive mode?" – Dennis Williamson Mar 05 '14 at 20:19
29

Try using Ctrl-[ instead of Esc.

What is the result of:

python -c "print ord(raw_input('char '))"

when you press Esc and Enter? It should be "27". What is the result of pressing Ctrl-V then Esc?

Have you checked all the settings in PuTTY to see if they're reasonable?

Are you using Bash on the remote system? Look at the output of

bind -p | grep -i '\\e' | less

and see if you see anything unusual. Do you have a file called ~/.inputrc? Look at its contents to see if anything is unusual.

Look at your ~/.vimrc and see if everything's OK, too.

Dennis Williamson
  • 106,229
  • 19
  • 167
  • 187
10

Maybe you are using the insert mode.

'insertmode' 'im' 'noinsertmode' 'noim'
boolean (default off)
Makes Vim work in a way that Insert mode is the default mode. Useful if you want to use Vim as a modeless editor. Used for |evim|.
[...]
- Use CTRL-O to execute one Normal mode command |i_CTRL-O|). When this is a mapping, it is executed as if 'insertmode' was off. Normal mode remains active until the mapping is finished. - Use CTRL-L to execute a number of Normal mode commands, then use Esc to get back to Insert mode. Note that CTRL-L moves the cursor left, like does when 'insertmode' isn't set. |i_CTRL-L|

I suggest editing ~/.vimrc to add the following line:

set noinsertmode         "disable insert mode
SandRock
  • 552
  • 5
  • 17
  • 1
    In my case it stuck in insert mode because i had accidentally used ` -y ` in commandline As said in manual: -y Start Vim in easy mode, just like the executable was called "evim" or "eview". Makes Vim behave like a click-and-type editor. To exit this "ease mode" just use CTRL + l (L lowercase) as said by +SandRock – ton Jan 22 '18 at 13:06
  • I accidently entered :set insertmode CTRL-L got me out of it. – ZaSter Nov 03 '20 at 19:37
  • I changed a command line from `diff -y` (side-by-side) to `vimdiff -y` and then wondered what was going on. – Michael Jaros Nov 12 '21 at 14:25
6

Find a strange way to quit:

copy some thing and paste it, then you can use <esc> or <ctrl-c> or <ctrl-[> to quit

see gif: https://i.stack.imgur.com/NBnns.gif

Sangria
  • 61
  • 1
  • 2
  • I had one vim session in a tmux pane start acting weirdly after accessing it via SSH from Windows - everything else, including other vim sessions in the same tmux session, were totally fine. `ctrl+c` etc. didn't work, but this did. – polm23 Nov 23 '22 at 04:14
0

I had this problem, but realized it was from accidentally changing the SCIM input mode to "Other - RAW CODE". I changed it back to English/Keyboard and did not have any more problems.

  • While it wasn't SCIM for me, I had the same problem and it was fixed by launching the Gnome Language Settings dialog, which detected something wasn't installed correctly. After fixing that and rebooting my escape key worked again. – Haegin Mar 24 '22 at 14:30
0

The top answer didn't work for me here and even ctrl + c couldn't get me out. If yours is as stuck as mine, here's what worked for me:

  1. Closed the current stuck terminal.
  2. Reconnected with a new terminal.
  3. Opened the file with Vim
  4. Got a notice that it was already being edited.
  5. It gave me the option of R for recovery which I chose.
  6. Back into vim for the file without issue.
Wes
  • 101
  • 2