Skip to content

Commit 821fcf2

Browse files
committed
Introduce triple bang syntax to remove triggers
In a snippets file, `snippet!!! foo` will remove the trigger from the current lookup for the current context. Load order still matters. This is useful to override a series of triggers with different descriptions, and turn that into a single trigger, so that you don't have to choose.
1 parent ee433e4 commit 821fcf2

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

autoload/snipMate.vim

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,12 @@ fun! snipMate#ReadSnippetsFile(file) abort
196196
if line[:6] == 'snippet'
197197
let inSnip = 1
198198
let bang = (line[7] == '!')
199-
if bang
199+
if bang "!!
200200
let bang += line[8] == '!'
201201
endif
202+
if bang "!!!
203+
let bang += line[9] == '!'
204+
endif
202205
let trigger = strpart(line, 8 + bang)
203206
let name = ''
204207
let space = stridx(trigger, ' ') + 1
@@ -314,7 +317,13 @@ endfunction
314317

315318
function! snipMate#SetByPath(dict, trigger, path, snippet, bang, snipversion) abort
316319
let d = a:dict
317-
if a:bang == 2
320+
if a:bang == 3
321+
unlet! d[a:trigger][a:path]
322+
if len(d[a:trigger]) == 0
323+
unlet! d[a:trigger]
324+
endif
325+
return
326+
elseif a:bang == 2
318327
unlet! d[a:trigger]
319328
return
320329
elseif !has_key(d, a:trigger) || a:bang == 1

doc/SnipMate.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ overridden on a per-snippet basis by defining the snippet with a bang (!): >
255255
Two bangs will remove the trigger entirely from SnipMate's lookup. In this
256256
case any snippet text is unused.
257257

258+
Three bangs will remove the trigger from the current scope. In this
259+
case any snippet text is unused.
260+
258261
Note: Hard tabs in the expansion text are required. When the snippet is
259262
expanded in the text and 'expandtab' is set, each tab will be replaced with
260263
spaces based on 'softtabstop' if nonzero or 'shiftwidth' otherwise.

0 commit comments

Comments
 (0)