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

Re: fast proto-typing

Expand Messages
  • Antoine J. Mechelynck
    ... Note that Ctrl-X and Ctrl-Z are already in use. (For Ctrl-Z there are the synonyms :sus[pend] or :st[op] which I find easier to remember. Ctrl-X is
    Message 1 of 6 , Jul 2, 2004
      Dave Silvia <dsilvia@...> 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.

      Note that Ctrl-X and Ctrl-Z are already in use. (For Ctrl-Z there are the
      synonyms ":sus[pend]" or ":st[op]" which I find easier to remember. Ctrl-X
      is used to decrement a number field, I use it a lot. Of course, for the
      people who use these commands, any key or key combo they don't use can be
      used instead.

      In general, the safest keys for the {lhs} of user mappings in (g)vim are the
      function keys, except F1 (help) and F10 (menu). Also, modifiers (Ctrl,
      Shift, Alt) on them are often more portable than on other keys (for
      instance, some keyboard drivers cannot distinguish Tab from Ctrl-I or
      Ctrl-Shift-I, Enter from Ctrl-M or Ctrl-Shift-M, but they can recognise all
      8 possibilities when applied to a function key -- don't take may word for
      it, test it on your own system: each one is different). The function keys'
      only drawback (some people say) is the need for long fingers.

      Regards,
      Tony.
    • Dave Silvia
      Right, the choice of key mapping is user dependent, that s for sure. I just grabbed these because I don t use the default mapping and they re easy for me to
      Message 2 of 6 , Jul 2, 2004
        Right, the choice of key mapping is user dependent, that's for sure. I just
        grabbed these because I don't use the default mapping and they're easy for
        me to remember.

        My <C-Z> default maps to ':u' (undo). I think mswin.vim does this.

        I like the 'long fingers' description! I can well identify with it!

        thx,
        Dave S.

        -----Original Message-----
        From: Antoine J. Mechelynck [mailto:antoine.mechelynck@...]
        Sent: Friday, July 02, 2004 8:32 PM
        To: Dave Silvia; vim@...
        Subject: Re: fast proto-typing


        Dave Silvia <dsilvia@...> 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.

        Note that Ctrl-X and Ctrl-Z are already in use. (For Ctrl-Z there are the
        synonyms ":sus[pend]" or ":st[op]" which I find easier to remember. Ctrl-X
        is used to decrement a number field, I use it a lot. Of course, for the
        people who use these commands, any key or key combo they don't use can be
        used instead.

        In general, the safest keys for the {lhs} of user mappings in (g)vim are the
        function keys, except F1 (help) and F10 (menu). Also, modifiers (Ctrl,
        Shift, Alt) on them are often more portable than on other keys (for
        instance, some keyboard drivers cannot distinguish Tab from Ctrl-I or
        Ctrl-Shift-I, Enter from Ctrl-M or Ctrl-Shift-M, but they can recognise all
        8 possibilities when applied to a function key -- don't take may word for
        it, test it on your own system: each one is different). The function keys'
        only drawback (some people say) is the need for long fingers.

        Regards,
        Tony.
      • Antoine J. Mechelynck
        Dave Silvia wrote: [...] ... [...] mswin.vim maps it to u (no colon), a Normal-mode command, not an Ex-command. Well, if someday you feel
        Message 3 of 6 , Jul 2, 2004
          Dave Silvia <dsilvia@...> wrote:
          [...]
          > My <C-Z> default maps to ':u' (undo). I think mswin.vim does this.
          [...]

          mswin.vim maps it to u (no colon), a Normal-mode command, not an Ex-command.

          Well, if someday you feel like junking mswin. vim, don't hesitate. It is
          there for the people who want it of course, but IMHO the automatic installer
          ought not to include it in the default vimrc, even on Windows. AFAIK,
          everything that mswin accomplishes can be done with no more keystrokes and
          in a more portable (more vim-like) manner without it. /And/ it masks useful
          keys like Ctrl-C (interrupt becomes Copy) Ctrl-A (Increment field becomes
          Select all), Ctrl-V (Block visual or Literalize becmes Paste), ... All those
          key combos are mentioned steadily in the docs with their "vim" meanings, and
          the need to use other keyss (Ctrl-Break for Ctrl-C, Ctrl-Q for Ctrl-V) when
          mswin.vim is in use is mentioned only in passing.

          As for the "behave mswin" command issued by mswin.vim (its least
          controversial part), I prefer settings which are about halfway between
          "behave mswin" and "behave xterm" so it is also of little use to me. (YMMV.)

          mswin.vim's only (doubtful) utility IMHO is to teach people the need to
          customize their vimrc (and remove the line which says "source
          $VIMRUNTIME/mswin.vim" or "runtime mswin.vim").

          Regards,
          Tony.

          P.S.
          "::behave mswin" is equivalent to
          set selectmode=mouse,key
          set mousemodel=popup
          set keymodel=startsel,stopsel
          set selection=exclusive

          "behave xterm", to
          set selectmode=
          set mousemodel=extend
          set keymodel=
          set selection=inclusive

          I use
          set selectmode=mouse,key
          set mousemodel=popup
          set keymodel=startsel
          set selection=inclusive

          Vim defaults (with -u NONE -N) to:
          set selectmode=
          set keymodel=
          set selection=inclusive
          if has("dos16")
          \ || has("dos32")
          \ || has("win16")
          \ || has("win32")
          \ || has("win64")
          set mousemodel=popup
          else
          set mousemodel=extend
          endif
        • Benji Fisher
          ... I am not sure what your question is, but I suggest using one function and one key mapping instead of two: function s:DoIt() update if &ft == vim source %
          Message 4 of 6 , 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()
            update
            if &ft == "vim"
            source %
            elseif &ft =~ "sh$"
            execute "!" . expand("%:p")
            else
            echo "I do not know how to execute this file type."
            endif
            endfunction

            HTH --Benji Fisher
          • Dave Silvia
            There 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$,
            Message 5 of 6 , Jul 5, 2004
              There 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).

              I suppose:

              function DoIt()
              update
              if &ft == "vim"
              source %
              else
              let execScriptPath="!".expand("%:p")
              execute execScriptPath
              endif
              endfunction

              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.

              thx,
              Dave S.

              -----Original Message-----
              From: Benji Fisher [mailto:benji@...]
              Sent: Monday, July 05, 2004 7:55 AM
              To: vim@...
              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
              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()
              update
              if &ft == "vim"
              source %
              elseif &ft =~ "sh$"
              execute "!" . expand("%:p")
              else
              echo "I do not know how to execute this file type."
              endif
              endfunction

              HTH --Benji Fisher
            Your message has been successfully submitted and would be delivered to recipients shortly.