DEV Community 👩‍💻👨‍💻

Cover image for VIM | Getting rid of ESC key to switch to Normal mode
Ian Borla
Ian Borla

Posted on

VIM | Getting rid of ESC key to switch to Normal mode

It's important that you place your hands in a correct position to reach different keyboard keys, but it has been a pain for me ever since to reach the ESC key just to switch to normal mode.

Some say you have to remap the CAPSLOCK key with ESC, but that doesn't work for me since I need the CAPSLOCK key sometimes if I need to write capitalized phrases or sentences.

Obviously, remap is the only solution. With this, I can place my hands in one place, and not stressing my fingers to reach certain keys.

You can put this in your .vimrc

" Press nn to return to normal mode when in insert mode
inoremap ii <ESC>
inoremap <ESC> <NOP>

" Press ii to return to normal mode when in visual mode
vnoremap ii <ESC>
vnoremap <ESC> <NOP>

" Press ii when in Command mode, to go back to normal mode
cnoremap ii <ESC>

The code above will allow you to use ESC functionality when pressing ii on these modes:

  • Insert mode
  • Visual mode
  • Command mode

This doesn't mean that you can't use the ESC, it's still usable but if you prefer switching to normal mode, then ii is the key to press.

It will take some time to train your hands and build that muscle memory, but once you have, I can assure you that it's worth it.


Saving your changes, instead of :w or :w!, you can either map this with your leader key:

noremap <Leader>s :update<CR>


" Press ww to do a w!
inoremap ww <ESC>:w!<CR>
" nnoremap ww <ESC>:w!<CR>
vnoremap ww <ESC>:w!<CR>
" Press nww to do a save on normal mode
nnoremap nww <ESC>:w!<CR>

This will allow you to save your changes without going to the command mode.

For Insert mode, press ww to save your changes.
When in Normal mode, press nww to save your changes.
Lastly on Visual mode, ww to save your changes.

I hope the remapped keys will help you to be more efficient when editing files on Vim.

Thank you for your time!

Top comments (4)

codenutt profile image

Solid. I use jk myself, but ii seems pretty smart too 👍🏼

benborla profile image
Ian Borla

Nice! I did not think of that, maybe I'll use jk on some other shortcuts. Thank you!

codenutt profile image


bmstschneider profile image

I'm using jj pretty similar to jk. but also, i'm using vscode vim

18 Useful Github Repositories Every Developer Should Bookmark

>> Check out this classic DEV post <<