An iTerm2 shortcut for a little productivity boost

2018-11-12

I still love Elixir and reach for it when hobby time permits. Elixir's pipe operator |> is a boon for code readability. As time went on, I wanted it to be easier to type.

I experimented with a few different Vim mappings to make it more comfortable and eventually landed on the following in my ~/.vim/ftplugin/elixir.vim file:

" type ctrl+return to start a new line with |>
inoremap <buffer> <F13> <ESC>o\|><space>
nnoremap <buffer> <F13> o\|><space>

" type ctrl+\ to add an inline |>
inoremap <buffer> <C-\> \|>
nnoremap <buffer> <C-\> A<space>\|><space>

Now any time Vim receives an F13 keypress, it creates a new line starting with |> and I can start typing the next part of the pipeline.

Wait, F13? My keyboard stops at F12! How is this better than manually starting a new line and typing |>? Fortunately iTerm2 makes it easy to trigger F13 with a custom Key Mapping.

iTerm2 custom Key Mapping

(That's [25~ if you're copying and pasting.)

As you can see, I've mapped ctrl+return to send the escape sequence for F13 in iTerm2.

Since I've rebound caps locks to control, ctrl+return is a very convenient combo to press. ctrl+\ is conveniently physically close to ctrl+return so I find the mental mapping as a similar (but slightly different) concept both memorable and pleasing.

I'll admit this seems silly, but these sorts of optimizations for ergonomics keep things flowing.


If you're asking why I don't just map ctrl+return in Vim itself, the answer is
that terminal Vim can't distinguish ctrl+return from normal return (though
this can vary by terminal emulator).

Do you have a better suggestion or use a similar approach for your preferred terminal emulator? Hit me up on twitter @semanticart.

My goofy face

Hi, I'm Jeffrey Chupp.
I solve problems, often with code.