Notes

Setting up Vim and Tmux

Edit on GitHub

Armbian
2 minutes
 1#!/bin/bash
 2
 3install_tmux () {
 4	# install Tmux
 5	sudo apt update 
 6	sudo apt install -y tmux
 7
 8	# create a custom Tmux conf file (~/.tmux.conf)
 9	touch $HOME/.tmux.conf
10	# macOS: ~/.tmux-osx.conf
11	
12# add config for 256 colors
13	echo -e "
14# 256 Colors
15set -g default-terminal \"screen-256color\"
16" >> $HOME/.tmux.conf
17	
18	# make an alias to `tmux -2` to force 256 color terminal
19	echo -e "alias tmux='tmux -2'" > $HOME/.bashrc
20}
21
22configure_vim() {
23# cerate custom Vim config file
24touch $HOME/.vimrc
25
26# create custom dirs
27mkdir -p $HOME/.vim/colors
28
29# fetch and save Sublime Monokai colorscheme
30curl https://raw.githubusercontent.com/ErichDonGubler/vim-sublime-monokai/master/colors/sublimemonokai.vim > $HOME/.vim/colors/sublimemonokai.vim
31
32# fetch and save Tommorow Night colorscheme
33curl https://raw.githubusercontent.com/chriskempson/tomorrow-theme/master/vim/colors/Tomorrow-Night.vim > $HOME/.vim/colors/tomorrownight.vim
34
35# Set basic config in order for Sublime Monokai theme to work
36echo 't_Co=256 \nsyntax on \ncolorscheme sublimemonokai' >> $HOME/.vimrc
37}
38
39install_tmux
40configure_vim
41
42# TODO
43# fetch conf files from here: https://github.com/aamnah/dotfiles
44
45# REFERENCES
46# https://github.com/tmux/tmux/wiki/FAQ

Colorscheme not showing up as expected

This has to do with 256 colors. Older terminals only supported 8 or 16 colors. Even now, some Terminals (and terminal emulators) may have to be told explicitly to use 256 colors even if they support it. (xterm does). If you use an emulator like tmux, you’ll have to tell tmux as well to use 256 colors.

This has happened to me on an Armbian system. The same Vim colorscheme that looked classy on macOS refused to work on Debian. Turns out Vim needs to be told to use 256 colors. Then it worked in xterm, but the ugliness continued when i’d open Vim inside tmux, so i had to set 256 color settings to tmux as well.

1# ~/.vimrc
2t_Co=256
3
4# ~/.tmux.conf
5set -g defalt-terminal "screen-256color"

You can also open tmux with 256 colors using the -2 flag:

1# -2            Force tmux to assume the terminal supports 256 colours.
2tmux -2
  • make tmux an alias to tmux -2
  • echo $TERM to see what Terminal you have
  • t_Co=256 let’s Vim use 256 colors in Terminals that support it. Without it Vim will only show 8 or 16 different colors. I needed to add this on an Armbian setup in order for the Monokai theme to work.