Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim script: how to execute a command in a vim function

Tags:

vim

Why does the following:

let s:colorschemes = ['synic', 'ir_black']
let s:colorscheme_idx = 0

function! RotateColorscheme()
  let s:colorscheme_idx += 1
  let s:name = s:colorschemes[s:colorscheme_idx]
  echo s:name
  colorscheme s:name
endfunction

not execute the colorscheme? Vim complains with the following error 'cannot find colorschem s:name'. How do I tell it that I want it to derefence that variable and not apply it literally to :colorscheme?

like image 858
sashang Avatar asked Sep 29 '11 12:09

sashang


People also ask

How do I use command F in Vim?

If you press "F", Vim will move the cursor backwards instead of forward. Given the previous sentence, if pressed "Fq", and the cursor was at the end of the line, it would move to the "q" in "quick".

How do I use echo in Vim?

Try out echo by running the following command: :echo "Hello, world!" You should see Hello, world! appear at the bottom of the window.

What is let G in Vim?

b: local to the current buffer. l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.


1 Answers

Have a look at this script from vim.wikia.com which does pretty much what you are asking for.

Key-line seems to be this one:

let nowcolors = 'elflord morning desert evening pablo'
  execute 'colorscheme '.split(nowcolors)[i]
like image 56
Fredrik Pihl Avatar answered Nov 08 '22 21:11

Fredrik Pihl