Вопрос

I'm trying to override the background of all colorschemes when using terminal windows - mostly because I find transparent terminal windows strangely exciting. All my best efforts of research points towards defining an autocmmand that will run everytime the colorscheme is changed. Currently the command looks like this:

autocmd ColorScheme * so rmbackground.vim

rmbackground.vim is a file of my own making which basically lists a bunch of hilightcommands like so:

hi Normal ctermbg=NONE
hi Comment ctermbg=NONE
...

Now the strange thing is that everything works correctly if I source the rmbackground.vim file manually, but the autocommand won't run as expected. Nor does it work if I specify a single hilight command as an autocmd instead of sourcing the whole rmbackground-file.

I feel very confused about the whole issue. below is my full vimrc and rmbackground.vim in case there are conflicts I'm not aware of. (The file is hideous at the moment since I've just started building my config but I hope you'll forgive me ;-) )

.vimrc

runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()

"Turn on syntax
if has("syntax")
  syntax on
endif

"Jump to last edited line
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

"Indent correctly
if has("autocmd")
  filetype plugin indent on
endif

set t_Co=256 "use 256 colors
let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : '', 'sp' : '' }

set background=light
colorscheme twilight

set showcmd     " Show (partial) command in status line.
set showmatch       " Show matching brackets.
set ignorecase      " Do case insensitive matching
set smartcase       " Do smart case matching
set hlsearch        " Highlight search-terms
set incsearch       " Incremental search
set autowrite       " Automatically save before commands like :next and :make
set hidden             " Hide buffers when they are abandoned
set mouse=a     " Enable mouse usage (all modes)

set history=1000

runtime macros/matchit.vim

set wildmenu
set wildmode=list:longest

set title
set scrolloff=3
set backupdir=~/.vim/tmp,~/.tmp,/var/tmp,/tmp
set directory=~/.vim/tmp,~/.tmp,/var/tmp,/tmp
set ruler

set backspace=indent,eol,start

set tabstop=4
set softtabstop=4
set shiftwidth=4
set shiftround "Round the indention nicely with other indents

set visualbell

"!autocmd
autocmd ColorScheme * so rmbackground.vim

rmbackground.vim

"Remove background set by colorscheme
hi Normal ctermbg=NONE
hi Comment ctermbg=NONE
hi Constant ctermbg=NONE
hi Special ctermbg=NONE
hi Identifier ctermbg=NONE
hi Statement ctermbg=NONE
hi PreProc ctermbg=NONE
hi Type ctermbg=NONE
hi Underlined ctermbg=NONE
hi Todo ctermbg=NONE
hi String ctermbg=NONE
hi Function ctermbg=NONE
hi Conditional ctermbg=NONE
hi Repeat ctermbg=NONE
hi Operator ctermbg=NONE
hi Structure ctermbg=NONE
Это было полезно?

Решение

The commands in .vimrc are executed sequentially. You're first setting :colorscheme, but the :autocmd comes only at the end.

Either you move the autocmd to before the :colorscheme command (so that it already applies to that), or you explicitly :source rmbackground.vim after the :colorscheme command, and have the :autocmd only for later dynamic changes.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top