vim function
Alan Young
alansyoungiii at gmail.com
Thu Aug 10 16:57:33 MDT 2006
Alex Esplin wrote:
> put this in your .vimrc: (mapping can be different if you want, I
> prefer to use a \ to start my function maps)
I prefer ftplugin so that this only works when I'm in a perl buffer (you
can put it in other filetypes as well if you want
> "map a shortcut to create an 'if' block
> map \if iif ()<CR>{<CR>}<Esc>?(<CR>a
This makes it so that you get this text regardless of which mode you're
in ... not good for ex or normal.
But your '?<CR>a' did give me a better idea about moving back to the parens:
-------------SNIP--------------------
function! AddParensBlock( KeyWord )
return a:KeyWord . " ( \<ESC>ma\<Insert> ) {\<CR>\<CR>}\<ESC>`aa"
endfunction
imap IF <C-R>=AddParensBlock( "if" )<Enter>
imap WH <C-R>=AddParensBlock( "while" )<Enter>
-------------SNIP--------------------
The return line should be one line.
> This will place the cursor in "insert mode" between the () in your
> 'if' statement. The curly brace placing is a matter of personal
> preference using:
I'm using 'equalprg=perltidy ...' to format so that doesn't really
matter to me.
> with the cursor in between the (). To get the cursor in the block in
> insert mode, place your "normal mode" cursor on the opening curly
> brace and press 'o'
Yeah, but what I'm looking for is someway to reduce that to a single
keystroke, in insert mode. Or at the most a key combo (Ctrl, Alt, etc.).
The way its setup now is I have to type '<ESC><DOWN>a<TAB>'. With yours
there would be an extra <DOWN> in there. So, e.g., I'm typing along and
my actual keystrokes at the moment are:
blah blah IFcondition<ESC><DOWN>a<TAB>write true handler
I'd like to cut that down to
blah blah IFcondition<KEY>write true handler
or even
blah blah IFcondition<C-KEY>write true handler
Alan
More information about the PLUG
mailing list