I have a key-mapping in VIM that looks like this:

map <F5> :silent !tmux send-keys -t 0:0 C-m "python %" C-m<cr>

When I press F5, vim runs my current Python script in tmux session 0, window 0. However, if window 0 is currently in a scroll state (i.e. Shift-PgUp or mouse scroll), tmux will run the command but will not scroll on new output.

How do I send a key to the tmux window that will break it out of scroll mode? (I want it to scroll on output)

Note: I normally get out of scroll-mode by pressing Esc, but I couldn't figure out how to send an Escape key using tmux send-keys. I tried sending C-[ but that didn't work.

1 Answer 1


You can send literal escape (and newline) with ANSI-C quoting (there's more about that here), e.g. to send escape to 0:0:

tmux send-keys -t 0:0 $'\e'

For your mapping, assuming I understand it correctly, you could do something like this:

map  <F5> :silent !tmux send-keys -t 0:0 $'\e'"python"$'\n'<CR>

Note that the escape will always be sent, so to work around the issue of the shell receiving the escape, you could send an extra newline:

map  <F5> :silent !tmux send-keys -t 0:0 $'\e'$'\n'"python"$'\n'<CR>
  • +1. Thanks for ANSI quoting tip! (I was looking for something like that). Unfortunately, sending the Esc code didn't work; I'm wondering if its because I'm running tmux in a terminal window, and the scrollback functionality is being supplied by the terminal emulator rather than tmux. In my mind, an Esc code is an Esc code, but it seems that either the terminal or tmux won't accept it.
    – Gilead
    Aug 18, 2012 at 16:30
  • You can check if the ESC is actually reaching tmux. Run: cat | od -t x2 inside tmux and execute: tmux send-keys $'\e\n\004' from somewhere else (that is ESC, NL, C-d). You should see 0a1b or 1b0a depending on your architecture endianess.
    – Thor
    Aug 18, 2012 at 16:44
  • Strike that, what you need is to enable scrollTtyOutput for your terminal, which is terminal dependent.
    – Thor
    Aug 18, 2012 at 16:52
  • 1
    I thought you meant break out of tmux scroll, just re-read your question and see that I was wrong. Will delete this answer shortly.
    – Thor
    Aug 18, 2012 at 16:54
  • It seems it is not enough with the scrollTtyOutput option for the terminal. If the command runs in tmux, it doesn't get registered as terminal output. I have a really ugly work around for that, I'll post it if nothing else is suggested.
    – Thor
    Aug 18, 2012 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .