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

1

6

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
Gnu answered 7/10, 2016 at 9:4 Comment(10)
see if this helps: vi.stackexchange.com/questions/2003/…Stig
Thanks, unfortunately it doesn't help - if I disable loading of .vimrc then I can't diagnose the problem, and if I disable the plugins/settings in .vimrc then I can't tell whether it was sourced!Gnu
Please show us your vimrc.Overhear
Thanks, see updated post.Gnu
After loading a session, do you see your .vimrc in :scriptnames output; i.e. is it sourced at all (but ineffectively)?Quotient
Thanks, ~/.vimrc is included in the :scriptnames output.Gnu
The problem is related to tmux - please see update in original post.Gnu
Are you absolutely sure it's the same Vim outside of tmux and in tmux?Overhear
Yes, in both cases, which vim returns /usr/bin/vimGnu
can you try typing :messages after you launch vim the first time? Maybe something is not run correctly at startup.Fendley
G
6

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"

Gnu answered 26/3, 2017 at 13:15 Comment(2)
Please forgive my ignorance, but where should I put the line export TERM...? Also, it is recommended not to change TERM: github.com/tmux/tmux/wiki/FAQCthrine
@Yankee export TERM... is a generic command that sets the TERM environment variable. Where you put it depends on your setup, but likely options are ~/.bashrc, ~/.profile or ~/.zshrc etcGnu

© 2022 - 2024 — McMap. All rights reserved.