I've just created my first VIM script, I wrote it in Python. It's a simple script to switch color schemes from a directory (/vim/etc/colors). I would like to know how to send a notification after the color scheme changed with the name of the selected color scheme to the vim 'statusline'.
rson gave an answer to my question, here is an updated (and debugged) version of the script for who is interested (works fine as far as I can test)
Implemented (kind of) the suggestions of AI and Caleb, thanks!:
" toggleColorScheme 0.9 (l) 2009 by Jasper Poppe <[email protected]>
" cycle through colorschemes with F8 and Shift+F8
nnoremap <silent><F8> :call ToggleColorScheme("1")<CR>
nnoremap <silent><s-F8> :call ToggleColorScheme("-1")<CR>
" set directory with color schemes to cycle through
let g:Toggle_Color_Scheme_Path = "/etc/vim/colors"
function! ToggleColorScheme(paramater)
python << endpython
import vim
import os
paramater = (vim.eval('a:paramater'))
scheme_path = vim.eval('g:Toggle_Color_Scheme_Path')
colorschemes = [color.split('.')[0] for color in os.listdir(scheme_path) if color.endswith('.vim')]
colorschemes.sort()
if not vars().has_key('position'):
start_scheme = vim.eval('g:colors_name') + '.vim'
if start_scheme in colorschemes:
position = colorschemes.index(start_scheme)
else:
position = 0
position += int(paramater)
position %= len(colorschemes)
vim.command('colorscheme %s' % colorschemes[position])
vim.command('redraw | echo "%s"' % colorschemes[position])
vim.command('return 1')
endpython
endfunction