Loading ...
Sorry, an error occurred while loading the content.

51497Re: fast proto-typing

Expand Messages
  • Benji Fisher
    Jul 5, 2004
      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 these
      > 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()
      > update
      > source %
      > endfunction
      > map <C-Z> :call <SID>SoIt()<CR>
      > amenu &File.E&xecute\ Current\ Buffer<TAB><C-X> :call <SID>ExecIt()<CR>
      > function s:ExecIt()
      > update
      > let execScriptPath="!".expand("%:p")
      > execute execScriptPath
      > endfunction
      > 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 execute
      > my whole script and exercising the function I'm writing, I just open another
      > buffer 'test.vim' and put in something like this:
      > function! Equal(var1,var2)
      > return a:var1 == a:var2
      > endfunction
      > 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 'Hit
      > any key to close this window...'. In UNIX, shell script execution from vim
      > 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:

      function s:DoIt()
      if &ft == "vim"
      source %
      elseif &ft =~ "sh$"
      execute "!" . expand("%:p")
      echo "I do not know how to execute this file type."

      HTH --Benji Fisher
    • Show all 6 messages in this topic