]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/autoload/togglebg.vim
Updates w/new configs
[rbdr/dotfiles] / vim / autoload / togglebg.vim
1 " Toggle Background
2 " Modified: 2011 Apr 29
3 " Maintainer: Ethan Schoonover
4 " License: OSI approved MIT license
5
6 if exists("g:loaded_togglebg")
7 finish
8 endif
9 let g:loaded_togglebg = 1
10
11 " noremap is a bit misleading here if you are unused to vim mapping.
12 " in fact, there is remapping, but only of script locally defined remaps, in
13 " this case <SID>TogBG. The <script> argument modifies the noremap scope in
14 " this regard (and the noremenu below).
15 nnoremap <unique> <script> <Plug>ToggleBackground <SID>TogBG
16 inoremap <unique> <script> <Plug>ToggleBackground <ESC><SID>TogBG<ESC>a
17 vnoremap <unique> <script> <Plug>ToggleBackground <ESC><SID>TogBG<ESC>gv
18 nnoremenu <script> Window.Toggle\ Background <SID>TogBG
19 inoremenu <script> Window.Toggle\ Background <ESC><SID>TogBG<ESC>a
20 vnoremenu <script> Window.Toggle\ Background <ESC><SID>TogBG<ESC>gv
21 tmenu Window.Toggle\ Background Toggle light and dark background modes
22 nnoremenu <script> ToolBar.togglebg <SID>TogBG
23 inoremenu <script> ToolBar.togglebg <ESC><SID>TogBG<ESC>a
24 vnoremenu <script> ToolBar.togglebg <ESC><SID>TogBG<ESC>gv
25 tmenu ToolBar.togglebg Toggle light and dark background modes
26 noremap <SID>TogBG :call <SID>TogBG()<CR>
27
28 function! s:TogBG()
29 let &background = ( &background == "dark"? "light" : "dark" )
30 if exists("g:colors_name")
31 exe "colorscheme " . g:colors_name
32 endif
33 endfunction
34
35 if !exists(":ToggleBG")
36 command ToggleBG :call s:TogBG()
37 endif
38
39 function! ToggleBackground()
40 echo "Please update your ToggleBackground mapping. ':help togglebg' for information."
41 endfunction
42
43 function! togglebg#map(mapActivation)
44 try
45 exe "silent! nmap <unique> ".a:mapActivation." <Plug>ToggleBackground"
46 exe "silent! imap <unique> ".a:mapActivation." <Plug>ToggleBackground"
47 exe "silent! vmap <unique> ".a:mapActivation." <Plug>ToggleBackground"
48 finally
49 return 0
50 endtry
51 endfunction
52
53 if !exists("no_plugin_maps") && !hasmapto('<Plug>ToggleBackground')
54 call togglebg#map("<F5>")
55 endif