Skip to content

Commit 0d3fbec

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 71250b0 commit 0d3fbec

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
@@ -223,9 +223,12 @@ fun! snipMate#ReadSnippetsFile(file) abort
223223
if line[:6] == 'snippet'
224224
let inSnip = 1
225225
let bang = (line[7] == '!')
226-
if bang
226+
if bang "!!
227227
let bang += line[8] == '!'
228228
endif
229+
if bang "!!!
230+
let bang += line[9] == '!'
231+
endif
229232
let trigger = strpart(line, 8 + bang)
230233
let name = ''
231234
let space = stridx(trigger, ' ') + 1
@@ -341,7 +344,13 @@ endfunction
341344

342345
function! snipMate#SetByPath(dict, trigger, path, snippet, bang, snipversion) abort
343346
let d = a:dict
344-
if a:bang == 2
347+
if a:bang == 3
348+
unlet! d[a:trigger][a:path]
349+
if len(d[a:trigger]) == 0
350+
unlet! d[a:trigger]
351+
endif
352+
return
353+
elseif a:bang == 2
345354
unlet! d[a:trigger]
346355
return
347356
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
@@ -256,6 +256,9 @@ overridden on a per-snippet basis by defining the snippet with a bang (!): >
256256
Two bangs will remove the trigger entirely from SnipMate's lookup. In this
257257
case any snippet text is unused.
258258

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

0 commit comments

Comments
 (0)