Sorry about the longwindedness  It may be a bit much to ask you to
read through to the question at the end.  But if you have the time
it will be appreciated on this end to hear any comments you may have. 

I'm going to describe a technique I've used extensively in another
editor. 

No religious wars are intended here.  Just a description of something
I've done in emacs that is quite handy and a big time saver in many
cases.

Emacs has a construct they call skeletons.  Its a way of coding in
elisp that allows you to construct complex formats, or patterns of
text or programming code and insert them into the buffer with a simple
keystroke.

Its really very similar to what is possible with `iab' constructs that
you can put into .vimrc and they will allow you to insert completions
when you type a few letters.

The difference is that trying to create a complicated format,
especially a long one, can get really complicated in the iab system.

What the emacs `skeleton' does is allow the complicated stuff to
be designed in elisp but it can be invoked by abbreviation completion
similar to iab.  It also allows you to control where the cursor ends
up.

In emacs you can have a set of abbreviations that will expand when you
hit the space bar.   Something like:

thrt<spc>  inserting the word `throughout'

In vims iab format, it would be very easy to do in ~/.vimrc:

   iab thrt throughout

Then whenever you wanted to type `throughout', you would type thrt<spc>
and `throughout' would be inserted instead of the thrt you typed.

Now imagine you wanted the same ease of insertion but the lengthy
chunk below, a starter script involving perls getopts like setup, is
what you needed inserted.  The `[X]' indicates where the cursor will
end up (inside the `if' clause of $opt_a)
(This is a bit overdone to emphasize the point)

  #!/usr/local/bin/perl
  
  # Keywords: ghtml.pl 
  #      [keydate:  092609_143119]
  # 
  # USAGE:  `./ghtml.pl'  
  # &&
  
  use strict;
  use warnings;
  
  if(!$ARGV || $ARGV[0] eq help){
    usage();
    exit;
  }
  ## ==== BEGIN Getopts section ====
  ## Declare vars inside our()
  our ($opt_a,$opt_b,$opt_c );
  use Getopt::Std;
  my $optstr ="a:b:c:";
  getopts($optstr);
  
  if($opt_a){
   [X]
  }
  if($opt_b){
   
  }
  if($opt_c){
   
  }
  ## ==== END Getopts section ====
  
  sub usage {
    print "
  
    Purpose:
    Usage: 
    ";
  }

Now that would be a bit much to attempt in an `iab' in vimrc.. Probably
not impossible but it would take some serious tinkering to get it
right.  And have the cursor end up like the `[X]' above.

In emacs you could use a skeleton to do the heavy lifting with the
full power of elisp to help you.  Then in the abbrev table which would
look like this for the simpler part I showed first.

In the `edit-abbrevs' buffer

This would be it for the easy one.

  [...]
  (text-mode-abbrev-table)

  "thrt"         0    "throughout"


This would be it for the big complex one

  [...]
  cperl-mode-abbrev-table

  "stp"          0   ""           hp-start-perl-getopts

   [ and a bunch of elisp somewhere in the load path that is the
   skeleton named `hp-start-perl-getopts']

  So you could insert all that code above by typing stp<spc>

(here is small simplified example of a skeleton to give the idea)

  (define-skeleton hp-pnarg
   "Insert an `if no ARGV' section"
    nil
  "if(!...@argv || $ARGV[0] eq \"help\"){
      usage();
      exit;
  }")

Inserts:

  if(!...@argv || $ARGV[0] eq "help"){
     usage();
     exit;
  }
  
In the abbrev table the link between inserting abbrevs and the
skeleton would look like below... the double quotes tells emacs
to insert whatever the skeleton hp-pnarg returns.:
 
 [...]
 cperl-mode-abbrev-table

 "pnarg"     30         ""      hp-pnarg

So typing pnarg<spc> would insert the skeleton named `hp-pnarg' 

Sorry to have taken so long to explain what I want to ask about.
But I suspect there is a process in vim that is similar.  Somewhere,
like .vimrc you write a function that will insert that pile 
perl code into a buffer.

But you can call it with a simple keystroke combo.. just like
when you invoke an `iab'.

Can anyone tell me how that would be setup in vim.  What tools to use
to get it done, and how to easily invoke the insertion... (from insert
mode if possible.) 

I'm not asking anyone to write the function or whatever its called
just describe the process and maybe a very simple example of what the
coding looks like, where it would go, and how to invoke it.


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to