Search code examples
vimterminaltmuxelementary-os

Vim line numbers and comments green instead of gray (tmux - solarized)


The default colors of vim in the terminal (tmux) still do not match those of gvim. I am using the pantheon terminal in elementary OS freya. This in combination with the solarized theme: http://ethanschoonover.com/solarized

When I do "echo $TERM" in tmux the output is: screen-256color

So that seems okay. From what I understand the $TERM value has to be properly defined in .bashrc. Tmux uses that and vim uses the TERM value it finds in tmux?

The colors I get are as follows: enter image description here

Within GVIM the line numbering and comments are gray?? How can I change this. The other colors also do not match?

My gvim looks like this: enter image description here

I have been looking a this problem for hours...

My configuration is as follows:

.bashr

# set a fancy prompt (non-color, unless we know we "want" color)
#case "$TERM" in
    #xterm-color) color_prompt=yes;;
#esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
    else
    color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

export EDITOR='vim'

### Start Tmux when opening terminal
if [[ ! $TERM =~ screen ]]; then
    exec tmux -2
fi

.tmux.conf

# reload source file to enable settings
#$ tmux source-file ~/.tmux.conf
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."

# Enable vi mode
set-window-option -g mode-keys vi

# Enable mouse control (clickable windows, panes, resizable panes)
set -g mouse-select-window on
set -g mouse-select-pane on
set -g mouse-resize-pane on

# switch panes using Alt-arrow without prefix
bind -n M-h select-pane -L
bind -n M-l select-pane -R
bind -n M-k select-pane -U
bind -n M-j select-pane -D

.vimrc

set background=dark
colorscheme solarized

When using pantheon $TERM = xterm

I also tried the vim csapprox plugin. This fixes it for the large part but the comments remain unreadable.

enter image description here


Solution

  • I fixed it using elementary tweaks. This enables me to choose to use the solarized theme in pantheon. All the other settings in the terminal are NOT needed.

    enter image description here

    The rest of my config is as follows:

    .bashrc

    export EDITOR='vim'
    
    ### Start Tmux when opening terminal
    if [[ ! $TERM =~ screen ]]; then
        exec tmux
    fi
    

    .tmux.conf

    # reload source file to enable settings
    #$ tmux source-file ~/.tmux.conf
    bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."
    
    # Enable vi mode
    set-window-option -g mode-keys vi
    
    # Enable mouse control (clickable windows, panes, resizable panes)
    set -g mouse-select-window on
    set -g mouse-select-pane on
    set -g mouse-resize-pane on
    
    # switch panes using Alt-arrow without prefix
    bind -n M-h select-pane -L
    bind -n M-l select-pane -R
    bind -n M-k select-pane -U
    bind -n M-j select-pane -D
    

    .vimrc

    let g:solarized_bold=1
    let g:solarized_italic=1
    let g:solarized_underline=1
    set background=dark
    colorscheme solarized
    

    When doing echo $TERM in tmux I get screen.

    As you can see I removed all the color 256 mentions and stuff is working. The comments are still dark but readable.

    Screen:

    enter image description here