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

51476RE: fast proto-typing

Expand Messages
  • Dave Silvia
    Jul 2, 2004
    • 0 Attachment
      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.
    • Show all 6 messages in this topic