I'd like to map a button to toggle Vim's background between transparent (to see stuff on other apps) and dark.

My current settings

I'm using onedark theme. There's currently no other background setting.

(Part of) my .vimrc:

set encoding=utf-8
set nocompatible
set rnu nu
set wildmode=longest,list,full
set wildmenu
filetype plugin on
syntax on

" Theme
colorscheme onedark

" Toggle transparent background
let t:is_transparent = 0
function! Toggle_transparent()
    if t:is_transparent == 0
        hi Normal guibg=NONE ctermbg=NONE
        let t:is_transparent = 1
        set background=dark
        let t:is_tranparent = 0
nnoremap <F1> : call Toggle_transparent()<CR>

Stuff I've tried

Manually using :hi Normal guibg=NONE ctermbg=NONE didn't work.

I found this script (I've added it to my vimrc) which also doesn't make my background transparent and the toggling seems to fail after the first couple of toggles:

let t:is_transparent = 0
 25 function! Toggle_transparent()
 26     if t:is_transparent == 0
 27         hi Normal guibg=NONE ctermbg=NONE
 28         let t:is_transparent = 1
 29     else
 30         set background=dark
 31         let t:is_tranparent = 0
 32     endif
 33 endfunction
 34 nnoremap <F1> : call Toggle_transparent()<CR>

What's wrong with hi Normal guibg=NONE ctermbg=NONE? How can I actually make


  • I'm using Manjaro KDE
  • I have gvim installed after vim
  • Transparency works fine in the terminal
  • 1
    You haven't told us the most important pieces of information... Why doesn't guibg=NONE ctermbg=NONE quite work? What do you see that's unexpected? Are you using gvim or terminal? Which OS/Desktop Environment? Which Terminal? Does transparency work in your terminal while you're using the shell? These would be useful in figuring out what could fix this for you... – filbranden Jan 13 '20 at 13:32
  • What do you mean by "didn't quite work"? – Rich Jan 14 '20 at 15:28
  • It changes the background color but doesn't quite make it transparent – John Zhau Jan 14 '20 at 16:06
  • I still don't understand what you mean by "doesn't quite make it transparent". Can you see through the terminal window? – Rich Jan 16 '20 at 17:41
  • I can't see through it. It's still full color. – John Zhau Jan 17 '20 at 3:59

The toggling in the terminal vim works fine for me if I do:

let t:is_transparent = 0                                                                        
function! Toggle_transparent_background()                                                       
  if t:is_transparent == 0                                                                      
    hi Normal guibg=#111111 ctermbg=black                                                       
    let t:is_transparent = 1                                                                    
    hi Normal guibg=NONE ctermbg=NONE                                                           
    let t:is_transparent = 0                                                                    
nnoremap <C-x><C-t> :call Toggle_transparent_background()<CR>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.