Tuesday, April 18, 2017

Re: Dynamically name commands in vimscript

Hi

> let s:modules = split(glob("modules/*"))
>
> for s:module in s:modules
> let s:module_name = split(s:module, "/")[-1]
> let s:prefix = toupper(s:module_name[0]) . s:module_name[1:]
>
> function! {s:prefix}()
> echo "inside " . s:prefix
> endfunction
> command! {s:prefix} call {s:prefix}()
> endfor
>
> I've tried with no luck:
> command! s:prefix call {s:prefix}()
> command! prefix call {s:prefix}()


You're looking for `:exe`

-> exe 'command! '.s:prefix.' call '.s:prefix.'()'

Regards,
--
Luc Hermitte

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: