I've set up my Vim to use the Solarized color scheme, but every time I open Vim, it shows the wrong colors. In addition, I have a line in my .vimrc
file that tells VIM to reload .vimrc
every time it's saved. When I open .vimrc
and only enter a single :w
in it, the color is automatically corrected.
This is the line in .vimrc
that enables that autoreload:
au BufWritePost .vimrc so ~/.vimrc
My Vim is version 7.4, compiled by myself, running on Ubuntu 14.04, inside a console whose has been changed to Solarized too.
For reference, this is my complete vimrc
file:
set nocompatible " be iMproved, required
filetype off " required
set shell=/bin/bash
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install bundles
"let path = '~/some/path/here'
"call vundle#rc(path)
" let Vundle manage Vundle, required
Bundle 'gmarik/vundle'
" The following are examples of different formats supported.
" Keep bundle commands between here and filetype plugin indent on.
" scripts on GitHub repos
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
"Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from http://vim-scripts.org/vim/scripts.html
"Bundle 'FuzzyFinder'
" scripts not on GitHub
"Bundle 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
"Bundle 'file:///home/gmarik/path/to/plugin'
" ...
"
Bundle 'L9'
Bundle 'scrooloose/nerdcommenter'
Bundle 'scrooloose/nerdtree'
"Bundle 'vim-scripts/Conque-Shell'
Bundle 'bling/vim-airline'
Bundle 'tpope/vim-fugitive'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'tpope/vim-surround'
Bundle 'ervandew/supertab'
Bundle 'kien/ctrlp.vim'
Bundle 'Raimondi/delimitMate'
"Bundle 'lepture/vim-css'
"Bundle 'groenewege/vim-less'
Bundle 'hail2u/vim-css3-syntax'
Bundle 'groenewege/vim-less'
Bundle 'Valloric/YouCompleteMe'
Bundle 'scrooloose/syntastic'
Bundle 'xolox/vim-session'
Bundle 'xolox/vim-misc'
Bundle 'altercation/vim-colors-solarized'
Bundle 'jelera/vim-javascript-syntax'
"Bundle 'pangloss/vim-javascript'
Bundle 'nathanaelkane/vim-indent-guides'
Bundle 'marijnh/tern_for_vim'
Bundle 'vim-scripts/JavaScript-Indent'
Bundle 'othree/javascript-libraries-syntax.vim'
filetype plugin indent on " required
" ycm
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_confirm_extra_conf = 0
" solarized theme
syntax enable
set background=dark
let g:solarized_termcolors=16
color solarized
" session manager
:let g:session_autosave = 'no'
" fix end & home buttons
set term=xterm-256color
" airline
set laststatus=2
let g:airline_powerline_fonts = 1
" list files for open
set wildmenu
" reselect visual block after indent
vnoremap < <gv
vnoremap > >gv
" easy split nav
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Y behav
map Y y$
"move on wrapeed lines
nnoremap j gj
nnoremap k gk
" clear search highlights
"noremap <silent><Leader>/ :nohls<CR>
" automatically reload vimrc when it's saved
au BufWritePost .vimrc so ~/.vimrc
" leader remap
let mapleader = ","
" jk as esc
inoremap jk <Esc>
inoremap kj <Esc>
" absolute line numbers in insert mode, relative otherwise for easy
" movement
"au InsertEnter * :set nu
"au InsertLeave * :set rnu
" show current file in nerd tree
map <silent> <C-s> :NERDTree<CR><C-w>p:NERDTreeFind<CR>
" show line numbers
set number
" search case insensitive
set ignorecase
set smartcase
" searhc incremental
set incsearch
" ctrl-p
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlPMRUFiles' " by default ctrlp opens in mru + files mode
set wildignore+=*/tmp/*,*.so,*.swp,*.zip " ignore shitty files
" ctrlp on enter, open in a tab. on c-e, open in current.
let g:ctrlp_prompt_mappings = {
\ 'AcceptSelection("e")': ['<c-e>', '<2-LeftMouse>'],
\ 'AcceptSelection("t")': ['<cr>'],
\ 'PrtCurEnd()': ['<c-q>'],
\ }
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
"let g:ctrlp_custom_ignore = {
"\ 'dir': '\v[\/]\.(git|hg|svn)$',
"\ 'file': '\v\.(exe|so|dll)$',
"\ 'link': 'some_bad_symbolic_links',
"\ }
" nerd tree auto open on start
autocmd vimenter * if !argc() | NERDTree | endif
" nerd tree toggle with c-n
map <C-n> :NERDTreeToggle<CR>
" nerd tree auto close when opening a file
let NERDTreeQuitOnOpen = 1
" map Q to repeat last macro
nnoremap Q @@
" fold on syntax
set foldmethod=indent
set foldcolumn=0
set foldlevel=1
" set mouse
set mouse=a
" tab = 4 spaces
set tabstop=4
set expandtab
set shiftwidth=4
" css complete fix
"fu! InsertTabWrapper(direction)
"let char_before = col('.') - 1
"if !char_before || getline('.')[char_before - 1] !~ '\k'
"return "\<tab>"
"elseif "backward" == a:direction
"return "\<c-p>"
"else
"return "\<c-n>"
"endif
"endfu
"inoremap <tab> <c-r>=InsertTabWrapper("forward")<cr>
"inoremap <s-tab> <c-r>=InsertTabWrapper("backward")<cr>
" javascript fold
au FileType javascript call JavaScriptFold()
" javascript libs
let g:used_javascript_libs = 'jquery,angularjs,angulaui'
" less compilation
nnoremap <Leader>m :w <BAR> !lessc % > %:t:r.css<CR><space>
" jump to last tab by leader tl
let g:lasttab = 1
nmap <leader>l :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
" map common typos
cabbrev W w
cabbrev Q q
cabbrev E e
" easier session
cabbrev S SaveSession
cabbrev O OpenSession
" nerd tree change current dir
let g:NERDTreeChDirMode = 2
" auto save the session on quit
let g:session_autosave = 'yes'
" auto save the session periodically
let g:session_autosave_periodic = 5
" fix backspace
set backspace=indent,eol,start
As an afterthought, I guess the background of texts in the first image are correct, but the background of the whole screen is wrong. I'm still wondering why.
color solarized
the second time, it's probably because of some setting that was different the second time the command was executed, that is, some setting that was made after thecolor solarized
command in your vimrc. The one that stands out to me isset term=xterm-256color
. Try putting that before the block beginning withsyntax enable
and see if that helps. Also, it's not a good idea to keep sourcing your vimrc as you do because you will wind up with multiple instances of your autocommands. E.g., execute:w
a few times, thenau TabLeave
.au tableave
I get multipletabpagenr()
s but does that mean it is executed multiple times? or what?