Vim, tmux, and Fish
Jan 18, 2023 @ 11:23 amI do most of my text editing with MacVim, but when I pair with people I like to use tmate.
tmate is just an easy way to connect tmux sessions with a remote person.
But this means that I go from coding in a GUI to coding in a terminal.
Normally this wouldn’t be a problem, but I had made a Fish alias that would open the MacVim GUI every time I typed vim
in the terminal.
Of course when I’m pairing via tmate, the other people cannot see the GUI, so I would have to remember a different command to open Vim.
Today I did about 10min of research to fix this problem and came up with the following Fish command:
$ cat .config/fish/functions/vim.fish
function vim --wraps='vim' --description 'open Vim'
if set -q TMUX # if we're in a TMUX session, open in terminal
command vim $argv
else
# Otherwise open macvim
open -a MacVim $argv;
end
end
All it does is open terminal Vim if I’m in a TMUX session, otherwise it opens the MacVim GUI.
Instead of putting up with this frustration for such a long time, I should have taken the 10 min required to fix the situation. This was a good reminder for me, and hopefully I’ll be better about it in the future!