I have some shortcut keys defined in iTerm, and I use them for key-mappings in Vim.

For example, I map Ctrl-Enter to send a ^[O2P escape code, which I then use to define a Ctrl-Enter key-mapping in my Vim:

enter image description here

set       <F13>=O2P
map       <F13> <C-CR>
inoremap <C-CR> <C-O>o

It works in a regular iTerm session, and in a screen session, but it not in a tmux session. How can I fix this to work with tmux? I'm transitioning away from screen and really enjoying tmux aside from this hangup.


I got this working by adjusting the escape codes to watch for in my .vimrc. I still wish I had a better understanding of how all this works, and why the sequence sent by tmux differs from what's sent outside of tmux, but this got everything working:

if &term =~ "screen"
  set  <F13>=[1;2P
  set  <F14>=[1;2Q
  set  <F15>=[1;2R
  set  <F16>=[1;2S
  set  <F17>=[1;5P
  set  <F18>=[1;5Q
  set  <F19>=[1;5R
  set  <F20>=[1;5A
  set  <F21>=[1;5B
elseif &term =~ "xterm"
  set  <F13>=O2P
  set  <F14>=O2Q
  set  <F15>=O2R
  set  <F16>=O2S
  set  <F17>=O5P
  set  <F18>=O5Q
  set  <F19>=O5R
  set  <F20>=[1;5A
  set  <F21>=[1;5B

" use some unused function key codes to
" make special key combos work in terminal
map  <F13> <C-CR>
map! <F13> <C-CR>
map  <F14> <S-CR>
map! <F14> <S-CR>

map  <F15> <C-Space>
map! <F15> <C-Space>
map  <F16> <S-Space>
map! <F16> <S-Space>

map  <F17> <C-BS>
map! <F17> <C-BS>

map  <F18> <M-Tab>
map! <F18> <M-Tab>
map  <F19> <M-S-Tab>
map! <F19> <M-S-Tab>

map  <F20> <C-Up>
map! <F20> <C-Up>
map  <F21> <C-Down>
map! <F21> <C-Down>
  • You haven't got any news on this and still do use this very solution? – A S May 9 '18 at 3:55
  • 1
    @AS my solution has evolved somewhat, and I moved it into a plugin. I'm also mostly using Linux these days though, so I haven't tried my latest version in iTerm. You could give it a try though: github.com/ivanbrennan/iota/blob/… – ivan May 9 '18 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.