This is a sort-of follow-up to my last post. It might help if you're reading this to take a look at my rant about vim colours. I've added this function to my ~/.vim/plugin/ folder: everything in the plugin folder is loaded into vim at startup.
" FILE: ~/.vim/plugin/myColour.vim
function MyColour()
" My preferred colours for various file types (":set filetype" to find the filetype)
" ( http://learnvimscriptthehardway.stevelosh.com/chapters/37.html "Dictionaries")
let myColours = {
\ 'html' : 'nightsky',
\ 'javascript': 'nightsky',
\ 'python' : 'tir_black',
\ 'rst' : 'nightsky',
\ 'sh' : 'tir_black',
\ 'vim' : 'shobogenzo',
\ 'yaml' : 'badwolf',
\ }
if has_key(myColours, &filetype)
let newcolour = get(myColours, &filetype)
execute "colorscheme " . newcolour
else
echom "No colour scheme found for this filetype"
endif
endfunction
I've also edited most of the files in ~/.vim/ftplugin/ to terminate with this:
" set my preferred colour scheme if this is the only buffer:
call IsSingleBuffer("call MyColour()")
See my last post for an explanation of IsSingleBuffer().
And I added a line to my ~/.vimrc file:
let mapleader = "-"
nnoremap <leader>c :call MyColour()<cr>
So typing "-c" in Normal mode will immediately switch the buffer (actually all buffers, vim colours are a PITA that way) to the preferred colour scheme for the current file type.