Wikia

Vim Tips Wiki

Watchlist Recent changes

Abbreviation that prompts whether to expand it or not

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)

ReferencesEdit

CommentsEdit

Pages on Vim Tips Wiki

Add a Page
1,590pages on
this wiki
Advertisement | Your ad here

Latest Photos

Add a Photo
71photos on this wiki
See more >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki