Remapping escape in sublime text and atom for vim key bindings

Avoiding the pull of the emacs rabbit hole, I decided sometime back to scale the lofty heights of the vi(m) learning curve. Alas, I have yet to reach the coveted plateau.

One of the challenges of vim is getting used to the various modes, especially toggling between normal and insert mode. In regular vim, exiting insert mode is accomplished by pressing the escape key or ctrl-c. However, it is common to remap the escape key to ‘jj’ or ‘kj’ or some other key combination that is easier to use. I chose kj, which in my .vimrc file is easily remapped using the inoremap command.

inoremap kj <Esc>

The challenge comes when trying to use a vim pluggin in another editor to not insert random ‘kj’s throughout the text.

Vim in sublime text editor:

To get basic vim key bindings for the sublime text editor, navigate to the

Preferences –> settings –>

In the user file enter the following line between the curly braces.

“ignored_packages”:[],

This enables the Vintage package by over riding the default settings. However, the only way out of insert mode is the escape key. Ctrl-C does not work. Skipping that, I want to bind escape to ‘kj’. For this we go to

Preference –> key bindings

This is a JSON file. Enter the following between the brackets. (If there are more than one key bindings, they should be separated by a comma. The following constitutes one key binding.)

 { “keys”: [“k”, “j”], “command”: “exit_insert_mode”, “context”: 
[
{ “key”: “setting.command_mode”, “operand”: false },
{ “key”: “setting.is.widget”, “operand”: false}
]
}

First, Thank you, Chris Sevilleja for writing this solution. If you are curious as to how to locate the “exit_insert_mode” command, go to

View –> Show Console

Then type Escape while in vim insert mode.

So there you have it.

Vim in Atom

In Atom, we have the vim-mode-plus package. To exit insert mode we have the addition of Ctrl-C along with the standard Escape key.

Keybindings in Atom are stored in a CSON file that can be accessed via

Atom menu –> keymap

The line we want to enter is

‘atom-text-editor.vim-mode-plus’: 
‘k j’: ‘vim-mode-plus:reset-normal-mode’

Note that the second line will need to be indented as per CSON indenting rules.

And so, we are in business. Whether in Sublime editor or in Atom, we can remap our key bindings so as to exit vim insert mode using the keys of our choosing.

Show your support

Clapping shows how much you appreciated Brian Wilson’s story.