freelance web developer

Menu

Idea: Sticky Shift-Enter in vim

I set up vim to use enter to get out of insert mode. This prevents frequently having to reach for the escape key or use a multi-key combination. To insert a new line while in insert mode, I now use shift-enter.

An idea I had this morning is to make shift-enter swap the shift-enter and enter bindings. This way, if I’m in the mode of writing something new without manipulating text, I can push shift-enter once to enter a newline, then push enter for each additional newline, and push shift-enter when I’m done to get out of insert mode.

To implement it, I created a function that toggles the bindings, and added a call to the function to my bindings for <S-Enter>.

That may be more desirable for me, too, actually. I haven’t tried this new setup for long enough to know whether it works well for me or not. To use Enter to get out of escape mode, you just remap it like so:

inoremap

In MacVim and gvim, shift-cr will enter a carriage return. This is how it is bound normally, and remapping by itself doesn’t change that. Inside a terminal window, vim can’t tell the difference between and shift-cr so it doesn’t work there.

I’m trying to do something similar with binding , or to — this works fine in gvim, but doesn’t seem to work inside a terminal — you mentioned that the terminal can’t tell the difference, do you know if there’s a workaround?

I don’t think there’s a way to get shift-enter working in the browser, but I’ve grown accustomed to hitting Enter and then o to insert a newline. I actually prefer to use that to shift-enter. It’s still two keys. In this case it’s typing a sequence of two keys rather than typing two keys at the same time.

I stopped using the code above and switched to simply remapping enter to Esc, and wrote a quick blog post about it.