(Replaced original technique and code with much better technique from the comments (updated to use iabbrev <expr> instead of <C_R>=). Added references and deleted comments.) |
(Changed category) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | {{review}} |
||
{{TipImported |
{{TipImported |
||
|id=650 |
|id=650 |
||
Line 9: | Line 8: | ||
|version=6.0 |
|version=6.0 |
||
|rating=5/5 |
|rating=5/5 |
||
− | |category1= |
+ | |category1=Abbreviations |
|category2=Map |
|category2=Map |
||
}} |
}} |
||
Line 21: | Line 20: | ||
endfunction |
endfunction |
||
− | iabbrev <expr> for < |
+ | iabbrev <expr> for <SID>Ask('for', "for () {\n}", 1) |
</pre> |
</pre> |
||
Revision as of 00:58, 29 November 2009
Tip 650 Printable Monobook Previous Next
created February 4, 2004 · complexity basic · author Yakov Lerner · version 6.0
You can define an abbreviation in such a way that it will ask whether to expand it or not. The trick is to define it as an expression, then have that expression ask for confirmation:
function! s:Ask(abbr,expansion,defprompt) let answer = confirm("Expand '" . a:abbr . "'?", "&Yes\n&No", a:defprompt) " testing against 1 and not 2, I correctly take care of <abort> return answer == 1 ? a:expansion : a:abbr endfunction iabbrev <expr> for <SID>Ask('for', "for () {\n}", 1)