Abbreviation that prompts whether to expand it or not
From Vim Tips Wiki
Tip 650 Previous Tip • Next Tip
Created: February 4, 2004 Complexity: basic Author: Yakov Lerner Minimum version: 6.0 Karma: 5/5 Imported from: Tip#650
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)
