Thursday, July 12, 2012

Re: source a file of commands as a script

On Wednesday, July 11, 2012 10:53:42 PM UTC-5, Bee wrote:
> source a file of commands as a script
>
> I have a file that has commands to convert vCard email addresses to
> tab delimited.
>
> The file has many commands and works great.
>
> I also tried bracketing all the commands with function! ... endf and
> then call the function. That also works great.
>
> One advantage to using the function, if there are multiple vCard files
> to convert I can call the function, but could just as easily source
> the script file.
>
> Another advantage might be if conditionals were used, but they are
> not.
>
> Is there an advantage one way or the other?
>
> It does not seem to run any faster as a function, surely i/o bound.
>
> Bill

Vim stores functions in memory, but I think it must re-read the file every time you source it (I may be wrong about that). So in theory if you were converting a lot of buffers in a loop, a function would be faster. But for one or two buffers done manually, you probably won't notice a difference.

Using a function is also a little "cleaner" but I don't know of any other differences.

Note that 2html.vim distributed with Vim is a script that you just source, either directly or via the :TOhtml command. Bram initially created this script (I maintain it now), so you're in good company if you use script files to just source.

--
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

No comments: