Last active
September 23, 2019 19:19
-
-
Save cowlicks/f81dce9017e232cc22ea to your computer and use it in GitHub Desktop.
vim + tmux command for getting a tight feedback loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TLDR; It saves the file in the current tmux pane, then runs `!!` the previous command in another tmux pane. | |
This enables a workflow like: | |
1. Edit code in pane #0 | |
2. Run some test command in pane #1 | |
3. Do more editing in pane #0 | |
4. Hit `,p` to re-run the command from 2. with the new edits | |
5. Repeat step 2. if you want to run a new test command. | |
# The command | |
:map ,p :w \|:! tmux send-keys -t 0:$(tmux display-message -p '\#I').1 C-l "\!\!" Enter Enter <cr><cr> | |
# Explanation | |
:map ,p = maps ,p to run this | |
:w = save the file currently in focus | |
\| = run another command | |
:! = run the following in a subshell | |
tmux send-keys -t = tmux command to send keys to a window addressed by -t <session#>:<window#>.<pane#> | |
0:$(tmux display-message -p '\#I').1 = the address for tmux to send the keys to. I'll break this down more: | |
0 = tmux session number (note: this is hardcoded here, could be made better and more dynamic) | |
$(tmux display-message -p '\#I') = gets the current tmux window | |
1 = pane number. I usually edit in pane 0 and run tests in pane 1. So this being hardcoded works fine for me. | |
C-l = Like ^L or Ctrl-L, clears the screen. Runs in the test pane | |
"\!\!" = puts `!!` in the test pane | |
Enter Enter = Presses enter twice in the test pane (twice is needed because in zsh !! Enter only inserts the previous command, so a second Enter is needed to run it) | |
<cr><cr> = <run vim command><back to focus on vim> | |
Other useful examples: | |
:map ,c :w \|:! tmux send-keys -t 0:$(tmux display-message -p '\#I').1 C-l C-c Enter Enter <cr><cr> | |
Use `,c` that just sends ^C. So I can have the same workflow as above, but with long commands. | |
:map ,t :w \|:! tmux send-keys -t 0:0.2 "clear && python manage.py test" Enter <cr><cr> | |
Simpler example, map `,t` to run `python manage.py test` in session 0, window 0, pane 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment