/tmuxline.vim

Simple tmux statusline generator with support for powerline symbols and statusline / airline / lightline integration

Primary LanguageVim scriptMIT LicenseMIT

tmuxline.vim

Simple tmux statusline generator with support for powerline symbols and vim/airline/lightline statusline integration

img

img

Features

  • use vim/vim-airline/lightline.vim colors, so tmux and vim share the same statusline colortheme
  • preloaded with stock themes and presets, which can be combined anyway you want
  • configure tmux statusline using a simple hash, in case stock presets don't meet your needs
  • create a snapshot .conf file which can be sourced by tmux, no need to open vim to set your tmux statusline

Quickstart

use vim's statusline colors

Use one of the vim_statusline_* themes (and optionally set in vimrc let g:tmuxline_powerline_separators = 0):

:Tmuxline vim_statusline_1
" or
:Tmuxline vim_statusline_2
" or
:Tmuxline vim_statusline_3

img

use vim-airline colors

Just start vim inside of tmux. airline's colors will be applied to tmux's statusline

img

Alternatively, you can set it manually using airline_* themes:

:Tmuxline airline
" or
:Tmuxline airline_insert
" or
:Tmuxline airline_visual

If you set airline theme manually, make sure the airline-tmuxline extension is disabled, so it doesn't overwrite the theme:

let g:airline#extensions#tmuxline#enabled = 0

use lightline.vim colors

Use one of the lightline_* themes:

:Tmuxline lightline
" or
:Tmuxline lightline_insert
" or
:Tmuxline lightline_visual

img

Usage

Set a a colortheme and a preset, both arguments are optional

:Tmuxline [theme] [preset]

After running :Tmuxline, create a snapshot file which can be sourced by tmux.conf on startup

:TmuxlineSnapshot [file]

Source the created snapshot in tmux.conf

# in tmux.conf
source-file [file]

# alternatively, check file exists before sourcing it in tmux.conf
if-shell "test -f [file]" "source [file]"

Note that :Tmuxline and :TmuxlineSnapshot are available only when vim is inside a tmux session.

Configuration

Stock preset

Set g:tmuxline_preset to a stock preset and run :Tmuxline

let g:tmuxline_preset = 'nightly_fox'
" or
let g:tmuxline_preset = 'full'
" or
let g:tmuxline_preset = 'tmux'
" other presets available in autoload/tmuxline/presets/*

Custom preset

Contents of the statusline are configured with a simple hash. Left section is configured with a, b, c, right with x, y, z. cwin and win affect the current (active) window and the in-active windows respectively.

let g:tmuxline_preset = {
      \'a'    : '#S',
      \'b'    : '#W',
      \'c'    : '#H',
      \'win'  : '#I #W',
      \'cwin' : '#I #W',
      \'x'    : '%a',
      \'y'    : '#W %R',
      \'z'    : '#H'}

img

tmux will replace #X and %X. Excerpts from tmux man page:

#H    Hostname of local host
#h    Hostname of local host without the domain name
#F    Current window flag
#I    Current window index
#S    Session name
#W    Current window name
#(shell-command)  First line of the command's output

string will be passed through strftime(3) before being used.

If the values of the hash g:tmuxline_preset hold an array, a powerline separator will be placed.

let g:tmuxline_preset = {
      \'a'    : '#S',
      \'win'  : ['#I', '#W'],
      \'cwin' : ['#I', '#W', '#F'],
      \'y'    : ['%R', '%a', '%Y'],
      \'z'    : '#H'}

img

tmux allows using any command in the statusline.

let g:tmuxline_preset = {
      \'a'    : '#S',
      \'c'    : ['#(whoami)', '#(uptime | cut -d " " -f 1,2,3)'],
      \'win'  : ['#I', '#W'],
      \'cwin' : ['#I', '#W', '#F'],
      \'x'    : '#(date)',
      \'y'    : ['%R', '%a', '%Y'],
      \'z'    : '#H'}

img

Separators

Use let g:tmuxline_powerline_separators = 0 to disable using powerline symbols

To fine-tune the separators, use g:tmuxline_separators:

let g:tmuxline_separators = {
    \ 'left' : '',
    \ 'left_alt': '>',
    \ 'right' : '',
    \ 'right_alt' : '<',
    \ 'space' : ' '}

Theme

Note that vim-airline has a tmuxline extension which by default sets airline's color theme onto tmuxline. If you don't want airline colors in tmuxline, set let g:airline#extensions#tmuxline#enabled = 0 in vimrc.

Modifying g:tmuxline_theme (details below) makes sense only if the airline-tmuxline is not enabled.

Use g:tmuxline_theme to configure the theme. g:tmuxline_theme can hold either a string (stock theme) or a hash (custom theme).

let g:tmuxline_theme = 'iceberg'
" or
let g:tmuxline_theme = 'zenburn'
" or
let g:tmuxline_theme = 'jellybeans'
" other themes available in autoload/tmuxline/themes/*

Alternatively, g:tmuxline_theme can be used to fine tune a custom theme:

let g:tmuxline_theme = {
    \   'a'    : [ 236, 103 ],
    \   'b'    : [ 253, 239 ],
    \   'c'    : [ 244, 236 ],
    \   'x'    : [ 244, 236 ],
    \   'y'    : [ 253, 239 ],
    \   'z'    : [ 236, 103 ],
    \   'win'  : [ 103, 236 ],
    \   'cwin' : [ 236, 103 ],
    \   'bg'   : [ 244, 236 ],
    \ }
" values represent: [ FG, BG, ATTR ]
"   FG ang BG are color codes
"   ATTR (optional) is a comma-delimited string of one or more of bold, dim, underscore, etc. For details refer to the STYLE section in the tmux man page

Installation

The plugin's files follow the standard layout for vim plugins.

  • Pathogen git clone https://github.com/edkolev/tmuxline.vim ~/.vim/bundle/tmuxline.vim
  • Vundle Bundle 'edkolev/tmuxline.vim'
  • NeoBundle NeoBundle 'edkolev/tmuxline.vim'
  • Vim-Plug Plug 'edkolev/tmuxline.vim'

Inspired by

Rationale

Vimscript wasn't my first choice of language for this plugin. Arguably, bash would have been better suited for this task. I chose vimscript because:

  • its data scructures (arrays, hashes) are better than their bash counterparts (easier to write, to maintain). So maintaining your tmux statusline as a vim hash would be easier
  • vim has (better) package managers

Somewhat-similar plugins:

  • powerline is a great project. Still, my Raspberry Pi chokes while executing python every 2 seconds (I haven't tried powerline's daemon mode). I also find it a bit hard to personalize
  • tmux-powerline doesn't focus on easy customization but on adding extra information (segments) in tmux (gmail, weather, earthquake warnings, etc)

License

MIT License. Copyright (c) 2013-2014 Evgeni Kolev.