user1578306
user1578306

Reputation: 99

How do I get the google cloud shell to recognize the Esc key correctly in vim

The Esc key is heavily used in vim to get back to normal mode from insert, command or visual mode. When you press the Esc key inside vim on the cloud shell the cursor changes shape and vim blocks. If you continually press on Esc key or if you click on the cursor itself then vim works again. I am in the habit of using the Esc key for changing back to normal in vim and so this makes using vim on the cloud shell very painful.

I do not have to use the Esc key (I can use Ctrl+c or Ctrl+[ and that works except that the banner prompt still claims vim is in INSERT mode when it has switched to NORMAL mode) but it is hard to change my habits.

vim cursor in INSERT mode just before pressing Esc key

vim cursor becomes hollowed out just after Esc is pressed but still in INSERT mode

NORMAL mode can be obtained by pressing Esc two or three more times and waiting

I have investigated remapping the Esc key inside vim but this messes up vim and I get strange behaviour (see warning not to change Esc key mapping in How to disable Esc and cursor keys in vim).

The backspace key does not work in vim either but that can be fixed inside .vimrc with:

inoremap <bs> <left><del>

If there is no fix for the Esc key mapping then I will have to force myself to learn not to use the Esc key. The best alternative to the Esc key on the cloud shell seems to be Alt+Space - as that invokes a return to NORMAL mode and switches off the --INSERT mode message on the bottom too.

Upvotes: 6

Views: 2917

Answers (2)

Learner
Learner

Reputation: 27

If you can't use esc there is still a way to exit vim. You can use Ctrl+o to perform one normal mode command. Then you will have the chance to use ':qa!' and exit.

If you want to keep editing your file a good solution is:

  1. Hit Ctrl+o to perform one command in normal mode
  2. Hit : to enter in normal mode
  3. Insert the command: inoremap jj <esc>
  4. Hit enter

After it the jj key combination will be remaped to <esc>.

Happy vimming!

Upvotes: 2

gusaki
gusaki

Reputation: 739

You'll have to hit escape twice (quickly) to enter ESC mode.

Upvotes: 0

Related Questions