Vim Tips Wiki
(init)
 
(format and give interim response)
Line 1: Line 1:
//added by ag@qs.cx
 
 
Hi,if I have a little time, I will try to clean up this post:
 
Hi,if I have a little time, I will try to clean up this post:
 
generally there is an issue with duplicated color schemes names, I've loaded 150 colo and then i could only view a few because 100 and 110 were the same (but loaded from different path), so there was only short loop between them.
 
generally there is an issue with duplicated color schemes names, I've loaded 150 colo and then i could only view a few because 100 and 110 were the same (but loaded from different path), so there was only short loop between them.
   
 
Here some working code:
 
Here some working code:
  +
<pre>
 
 
" Change the color scheme from a list of color scheme names.
 
" Change the color scheme from a list of color scheme names.
 
" Version 2010-09-12 from http://vim.wikia.com/wiki/VimTip341
 
" Version 2010-09-12 from http://vim.wikia.com/wiki/VimTip341
Line 26: Line 25:
 
let s:mycolors = ['slate', 'torte', 'darkblue', 'delek', 'murphy', 'elflord', 'pablo', 'koehler', 'solarized'] " colorscheme names that we use to set color
 
let s:mycolors = ['slate', 'torte', 'darkblue', 'delek', 'murphy', 'elflord', 'pablo', 'koehler', 'solarized'] " colorscheme names that we use to set color
   
"FIXME need to use global enumerator
+
"FIXME need to use global enumerator
 
let s:current = -1
 
let s:current = -1
   
Line 42: Line 41:
 
" let paths = []
 
" let paths = []
 
let paths_tofix = split(globpath(&runtimepath, 'colors/*.vim'), "\n")
 
let paths_tofix = split(globpath(&runtimepath, 'colors/*.vim'), "\n")
" FIXME ag@qs.cx duplicated color schemes - it doesnt - take a look /usr/share/.../murphy.vim and ~/vim/color/murphy.vim
+
" FIXME ag-at-qs.cx duplicated color schemes - it doesnt - take a look /usr/share/.../murphy.vim and ~/vim/color/murphy.vim
 
" for i in range(len(paths_tofix))
 
" for i in range(len(paths_tofix))
 
" if index(paths, paths_tofix[i]) == -1
 
" if index(paths, paths_tofix[i]) == -1
 
" call add(paths, paths_tofix[i])
 
" call add(paths, paths_tofix[i])
" echo paths_tofix[i]
+
" echo paths_tofix[i]
 
" endif
 
" endif
" endfor
+
" endfor
 
let paths = paths_tofix
 
let paths = paths_tofix
 
let s:mycolors = map(paths, 'fnamemodify(v:val, ":t:r")')
 
let s:mycolors = map(paths, 'fnamemodify(v:val, ":t:r")')
Line 114: Line 113:
 
endif
 
endif
 
endfunction
 
endfunction
 
   
 
"FIXME my mod - useful when you have 150 colour schemes
 
"FIXME my mod - useful when you have 150 colour schemes
Line 154: Line 152:
 
echo g:colors_name
 
echo g:colors_name
 
endfunction
 
endfunction
  +
</pre>
   
  +
--ag-at-qs.cx January 29, 2012
 
  +
:We generally don't use talk pages, preferring all comments to be on the tip page where people see them. Also, we do not keep comments indefinitely, but hope to eventually respond to any points raised and integrate them into the tip (and remove the comment). However, the talk page is a good place for something of this length and complexity so let's stay here for now (but there is no commitment to keep this page). I have not yet taken the time to work out what changes there are above, so can't say anything helpful at the moment. [[User:JohnBeckett|JohnBeckett]] 10:04, January 29, 2012 (UTC)
 
 
 
 
 
 
Write the first paragraph of your article here.
 
 
==Section heading==
 
 
Write the first section of your article here.
 
 
==References==
 
<!-- Put any help links you want here in a list as follows: -->
 
*{{help|toc}}
 
 
==Comments==
 

Revision as of 10:04, 29 January 2012

Hi,if I have a little time, I will try to clean up this post: generally there is an issue with duplicated color schemes names, I've loaded 150 colo and then i could only view a few because 100 and 110 were the same (but loaded from different path), so there was only short loop between them.

Here some working code:

" Change the color scheme from a list of color scheme names.
" Version 2010-09-12 from http://vim.wikia.com/wiki/VimTip341
" Press key:
"FIXME: i prefer F2 :P
"   F2                next scheme
"   Shift-F2          previous scheme
"   Alt-F2            random scheme
" Set the list of color schemes used by the above (default is 'all'):
"   :SetColors all              (all $VIMRUNTIME/colors/*.vim)
"   :SetColors my               (names built into script)
"   :SetColors blue slate ron   (these schemes)
"   :SetColors                  (display current scheme names)
" Set the current color scheme based on time of day:
"   :SetColors now
if v:version < 700 || exists('loaded_setcolors') || &cp
  finish
endif

let loaded_setcolors = 1
let s:mycolors = ['slate', 'torte', 'darkblue', 'delek', 'murphy', 'elflord', 'pablo', 'koehler', 'solarized']  " colorscheme names that we use to set color

"FIXME need to use global enumerator
let s:current = -1

" Set list of color scheme names that we will use, except
" argument 'now' actually changes the current color scheme.
function! s:SetColors(args)
  if len(a:args) == 0
    echo 'Current color scheme names:'
    let i = 0
    while i < len(s:mycolors)
      echo '  '.join(map(s:mycolors[i : i+4], 'printf("%-14s", v:val)'))
      let i += 5
    endwhile
  elseif a:args == 'all'
"    let paths = []
    let paths_tofix = split(globpath(&runtimepath, 'colors/*.vim'), "\n")
" FIXME ag-at-qs.cx duplicated color schemes - it doesnt - take a look /usr/share/.../murphy.vim and ~/vim/color/murphy.vim
"    for i in range(len(paths_tofix))
"      if index(paths, paths_tofix[i]) == -1
"        call add(paths, paths_tofix[i])
"        echo paths_tofix[i]
"      endif
"    endfor
    let paths = paths_tofix
    let s:mycolors = map(paths, 'fnamemodify(v:val, ":t:r")')
"    echo 'List of colors set from all installed color schemes (added ' . len(paths). ' schemes).'
    let g:colorschemes = len(paths)
  elseif a:args == 'my'
    let c1 = 'default elflord peachpuff desert256 breeze morning'
    let c2 = 'darkblue gothic aqua earth black_angus relaxedgreen'
    let c3 = 'darkblack freya motus impact less chocolateliquor'
    let s:mycolors = split(c1.' '.c2.' '.c3)
"    echo 'List of colors set from built-in names'
  elseif a:args == 'now'
    call s:HourColor()
  else
    let s:mycolors = split(a:args)
"    echo 'List of colors set from argument (space-separated names)'
  endif
endfunction

command! -nargs=* SetColors call <SID>SetColors('<args>')

"FIXME - i have not chosen my prefered set of colour schemes so i add all of them
execute "call <SID>SetColors('all')"

" Set next/previous/random (how = 1/-1/0) color from our list of colors.
" The 'random' index is actually set from the current time in seconds.
" Global (no 's:') so can easily call from command line.
function! NextColor(how)
  call s:NextColor(a:how, 1)
endfunction

" Helper function for NextColor(), allows echoing of the color name to be
" disabled.
function! s:NextColor(how, echo_color)
  if len(s:mycolors) == 0
    call s:SetColors('all')
  endif
  let missing = []
  let how = a:how
  for i in range(len(s:mycolors))
    if how == 0
      let s:current = localtime() % len(s:mycolors)
      let how = 1  " in case random color does not exist
    else
      let s:current += how
"      echoerr current . '/' . len(s:mycolors)
      if !(0 <= s:current && s:current < len(s:mycolors))
        let s:current = (how>0 ? 0 : len(s:mycolors)-1)
      endif
    endif
    try
      execute 'colorscheme '.s:mycolors[s:current]
      break
    catch /E185:/
      echoerr 'Could not locate colorscheme: ' . s:mycolors[s:current]
      call add(missing, s:mycolors[s:current])
    endtry
  endfor
  redraw
  if len(missing) > 0
    echo 'Error: colorscheme not found:' join(missing)
  endif
  if (a:echo_color)
    echo '[' . s:current . '] ' . g:colors_name
  endif
endfunction

"FIXME my mod - useful when you have 150 colour schemes
function! SetColor()
  let s:current = input("Enter number [0," . (len(s:mycolors) - 1) . "]: ")
  try
    execute 'colorscheme '.s:mycolors[s:current]
  catch
    call s:NextColor(1,1)
  endtry
endfunction
noremap <F7> :call SetColor()<CR>

inoremap <F2> <ESC>:call NextColor(1)<CR>i
inoremap <S-F2> <ESC>:call NextColor(-1)<CR>i
inoremap <A-F2> <ESC>:call NextColor(0)<CR>i

nnoremap <F2> :call NextColor(1)<CR>
nnoremap <S-F2> :call NextColor(-1)<CR>
nnoremap <A-F2> :call NextColor(0)<CR>

" Set color scheme according to current time of day.
function! s:HourColor()
  let hr = str2nr(strftime('%H'))
  if hr <= 3
    let i = 0
  elseif hr <= 7
    let i = 1
  elseif hr <= 14
    let i = 2
  elseif hr <= 18
    let i = 3
  else
    let i = 4
  endif
  let nowcolors = 'elflord morning desert evening pablo'
  execute 'colorscheme '.split(nowcolors)[i]
  redraw
  echo g:colors_name
endfunction

--ag-at-qs.cx January 29, 2012

We generally don't use talk pages, preferring all comments to be on the tip page where people see them. Also, we do not keep comments indefinitely, but hope to eventually respond to any points raised and integrate them into the tip (and remove the comment). However, the talk page is a good place for something of this length and complexity so let's stay here for now (but there is no commitment to keep this page). I have not yet taken the time to work out what changes there are above, so can't say anything helpful at the moment. JohnBeckett 10:04, January 29, 2012 (UTC)