I have two aliases in my ~/.bashrc to do this. If I'm in a Tmux pane, and want to switch colour schemes, I just source the relevant file, and update the THEME variable. Set -g window-active-style 'fg=colour238,bg=colour231' Set -g window-style 'fg=colour238,bg=colour253' Set -g pane-active-border-style "bg=colour253 fg=colour208" Set -g pane-border-style "bg=colour253 fg=colour244" In addition to ~/.tmux_nf, I have ~/.tmux_nf: # light colours Set -g window-active-style 'fg=colour252,bg=colour235' Set -g window-style 'fg=colour248,bg=colour234' Set -g pane-active-border-style "bg=colour234 fg=colour208" Set -g pane-border-style "bg=colour234 fg=colour244" These are the dark theme colours I have: # dark colours Set -g default-terminal 'screen-256color' These values may get overridden by a light scheme later: # source colorscheme ] &Īt the beginning of my ~/nf file, I start by sourcing a secondary Tmux file that contains the dark colours I've chosen. # check if we have been switched to light, else go dark This means that when we first launch a Tmux session, we will default to a dark theme: if command -v tmux>/dev/null then Once I've launched Tmux, I query the environment variable called 'THEME', if it's not equal to 'THEME=light' (or just doesn't exist), then we go with the dark theme and set the THEME variable accordingly. I find this works for me, but you may want to alter this step. In reality I keep them all in a single git repository with symbolic links from the home directory to allow me to keep my working environment synchronised across machines as described on this git repo.įirst, I've configured my ~/.bashrc such that it will automatically launch Tmux and attempt to connect to a session called 'main', or create it if it doesn't exist. Code implementation Step 1: Switching colours from inside a Tmux paneįor the purpose of this guide, I'll assume my various dot files are in my home directory. Existing and new Tmux panes and existing and new instances of Vim will check this variable and follow the scheme. Anytime I switch, be it from Vim or a Tmux pane, the variable will be updated. The way it works is that I define a Tmux environmental variable that keeps track of whether we have a light or dark colour scheme. ![]() I had exactly the same problem as you, and I have the following setup:ġa) The alias 'ol' switches both Vim and Tmux to light mode.ġb) The alias 'od' switches both Vim and Tmux to dark mode.Ģ ) 'Leader-o' toggles both Vim and Tmux between light and dark colour schemes. I pulled this answer from my blog Switch between light and dark mode in Vim and Tmux with one command
0 Comments
Leave a Reply. |