Dump to a file and automatically open the file in vim
This is sweet:
bind-key v 'capture-pane' \; \
capture-pane -S - \; \
save-buffer /tmp/tmux \; \
delete-buffer \; \
send-keys Escape 'ddivim /tmp/tmux' Enter
This solution supposes that your shell is in vi mode, so that:
- Escape goes into normal mode
ddclears any existing commandigoes into insert mode- then we run
vim /tmp/tmux
Tested in tmux 3.0.
Newline insertion on terminal wrap issue
One problem with this is that it inserts literal newlines on any line that would have been broken up due to terminal wrapping if output lines are longer than you terminal width. And we usually don't want that.
I tried to fix this with -J as mentioned here but that caused another problem, it started adding trailing space characters to each line.
Eric Cousineau proposes a workaround for that with sed, but I'd really rather avoid this as it would remove actual newlines emitted by the commands, which I want to be there.
Kind of the inverse of this was asked at: https://github.com/tmux/tmux/issues/422 Add capture-pane option to only preserve trailing spaces. Maybe the space thins is a fundamental terminal limitation?