Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim requires .vimrc to be sourced every time when running in tmux

I have made several changes to my .vimrc file, which includes several vim-plug plugins, some syntax/coloring options and some key mappings.

Whenever I open a new Vim session however, not all of these are being applied (most notably coloring and syntax highlighting). If I run :so ~/.vimrc the file gets sourced and the changes apply immediately. Obiously I don't want to have to do this every time I start vim.

Why are these changes not being applied automatically? (This is after a complete restart and new terminal/vim session).

Update
I've discovered this is related to tmux. When I run vim straight from terminal, .vimrc is applied as expected. If I run vim from inside a tmux session, then I have to manually source the file every time.

Any ideas how to solve this?

~/.vimrc contents:

" PLUGINS - see vim-plug
call plug#begin()
 Plug 'crusoexia/vim-monokai'
 Plug 'pangloss/vim-javascript'
 Plug 'crusoexia/vim-javascript-lib'
call plug#end()

" Enable Monokai colors
syntax on
colorscheme monokai
set t_Co=256

" Easy tab movement with keys 1|2
nmap 1 :tabp <enter>
nmap 2 :tabn <enter>

" Line Numbers
set number

" 2 space tabs
set tabstop=8 softtabstop=2 expandtab shiftwidth=2 smarttab
like image 644
duncanhall Avatar asked Oct 07 '16 09:10

duncanhall


1 Answers

In my case, tmux was overriding the TERM value until .vimrc was sourced.

Running echo $TERM in a regular shell gave xterm-256color, whereas running it in tmux gave screen.

The solution was to explicitly export the desired TERM value:

export TERM="xterm-256color"

like image 170
duncanhall Avatar answered Oct 21 '22 02:10

duncanhall