History Report a problem
Article Edit this page Discussion

Abbreviation that prompts whether to expand it or not

From Vim Tips Wiki

Jump to: navigation, search

Tip 650 Previous TipNext 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)

[edit] References

[edit] Comments

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pushing Daisies
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Godzilla
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Abbreviation that prompts whether to expand it or not"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation


.