vim function

Alan Young alansyoungiii at
Thu Aug 10 13:34:51 MDT 2006

I was showing my .vimrc last night to NUPM (and those who came early for
PLUG) and ran into problems with a function I was trying to create.  I
got it fixed and here it is:

function! AddBlock( KeyWord )

  return a:KeyWord . " {\<CR>\<CR>}\<ESC>bmbbb\<LEFT>\<Insert>"


imap IF <C-R>=AddBlock( "if (  )" )<Enter>
imap WH <C-R>=AddBlock( "while (  )") )<Enter>

Put this in your ftplugin/perl.vim file (whereever you have put it) and
while in insert mode you can type IF and you'll get the following:

if ( _ ) {


(the '_' is where the cursor will be).  The only problem I have with
this is moving to inside the block.  You can either use your arrow keys,
if they're mapped, or you can press <Esc>'b and you'll be placed on the
blank line between the curly braces.  There's got to be a better way.
Any ideas?


More information about the PLUG mailing list