51499RE: fast proto-typing
- Jul 5, 2004There was no question. Just sharing.
As it sits, with 2 functions/mappings I can source vim files with one and
any other file with the other (not just .sh$, but .pl, .plx, .bat, etc, as
well as files without extensions).
if &ft == "vim"
BTW, expand("%:p"), the ':p' is only necessary for UNIX in case the file is
not in $PATH. Windows always passes a full qualified path to command/cmd.
Still, I think I prefer 2 functions/mappings, since that puts the whole
burden of decision on ':so' or ':exec' on me. Who knows, there may be a
'vimsh' some day and then I'd be able to source or execute.
From: Benji Fisher [mailto:benji@...]
Sent: Monday, July 05, 2004 7:55 AM
Subject: Re: fast proto-typing
On Fri, Jul 02, 2004 at 07:54:06PM -0500, Dave Silvia wrote:
> I do a lot of fast proto-typing while authoring scripts. I can check
> out quickly using 'source' for vim scripts and 'execute' for shell scripts
> at the vim command line. However, I get a little tired of typing ':w' and
> ':source %' for vim scripts and ':w' and 'execute !%' for shell scripts.
> So, I added this to my personal ~/_vimrc.Dave (sourced last in my .vimrc)
> amenu &File.So&urce\ Current\ Buffer<TAB><C-Z> :call <SID>SoIt()<CR>
> function s:SoIt()
> source %
> map <C-Z> :call <SID>SoIt()<CR>
> amenu &File.E&xecute\ Current\ Buffer<TAB><C-X> :call <SID>ExecIt()<CR>
> function s:ExecIt()
> let execScriptPath="!".expand("%:p")
> execute execScriptPath
> map <C-X> :call <SID>ExecIt()<CR>
> Let's say I'm writing a function in a vim script and I want to return
> boolean based on whether or not 2 variables are equal. I think I can use
> the construct 'return var1 == var2', but I'm not sure. Rather than
> my whole script and exercising the function I'm writing, I just open
> buffer 'test.vim' and put in something like this:
> function! Equal(var1,var2)
> return a:var1 == a:var2
> let areEqual=Equal(2,2)
> echo areEqual
> Then I just source the file via the menu 'Source Current Buffer' choice or
> use my mapping of <C-Z>. I can then change the variables in the call to
> 'Equal' and see what happens. I find that Equal(2,2) returns 1,
> Equal(2,'hello') returns 0, and Equal(2,'2') returns 1 very quickly.
> Similarly with shell scripts.
> It works equally well in vim/gvim and UNIX/DOS-WINDOWS. In the case of
> shell scripts in gvim, a command window is brought up, with the prompt
> any key to close this window...'. In UNIX, shell script execution from
> ends with the usual 'Hit ENTER or type command to continue' prompt.
> I'm sure there's other ways to do it (I'd like to hear about them!). This
> one does work, tho', if you're interested.
> FYI & thx,
> Dave S.
I am not sure what your question is, but I suggest using one
function and one key mapping instead of two:
if &ft == "vim"
elseif &ft =~ "sh$"
execute "!" . expand("%:p")
echo "I do not know how to execute this file type."
HTH --Benji Fisher
- << Previous post in topic