Skip to main content
added 187 characters in body
Source Link
user786441
  • 681
  • 6
  • 5
      ┌ mirror of tabstop n°1
      │                          ┌ substitution
    ┌─┤┌─────────────────────────┤
(A) ${1/(".*)|.*/(?1:comment => )/} 


      └┤┌ tabstop n° 1
        mirror of tabstop n°1         ┌ placeholder text, on which you perform a substitution

(B) ${1:"some comment"}
      └┤└────────────┤
                     placeholder text,
   
   which fills the tabstop as long as you don't replace it 
    ┌─┤┌─────────────┤
(B) ${1:"some comment"}
  tabstop  1
                   

       ┌ mirror of tabstop n°1, 
 on which you perform a substitution
      ┌┤        ┌ beginning of substitution
    ┌─┤┌─────────────┤
(C) ${1/(".*)|.*/(?1:,
    )/}
    └─┤
      └ end of substitution
(A) ${1/(".*)|.*/(?1:comment => )/}
      └┤
        mirror of tabstop n°1, on which you perform a substitution

(B) ${1:"some comment"}
      └┤└────────────┤
                     placeholder text,
       │               which fills the tabstop as long as you don't replace it
        tabstop  1


       ┌ mirror of tabstop n°1, on which you perform a substitution
      ┌┤
(C) ${1/(".*)|.*/(?1:,
    )/}
      ┌ mirror of tabstop n°1
      │                          ┌ substitution
    ┌─┤┌─────────────────────────┤
(A) ${1/(".*)|.*/(?1:comment => )/} 


      ┌ tabstop n° 1
                    ┌ placeholder text,                                       
   which fills the tabstop as long as you don't replace it 
    ┌─┤┌─────────────┤
(B) ${1:"some comment"}
                       

      ┌ mirror of tabstop n°1 
                    ┌ beginning of substitution
    ┌─┤┌─────────────┤
(C) ${1/(".*)|.*/(?1:,
    )/}
    └─┤
      └ end of substitution
deleted 50 characters in body
Source Link
user786441
  • 681
  • 6
  • 5
${1/(".*)|.*/(?1:comment => )/}${1:"some comment"}${1/(".*)|.*/(?1:,
)/}home => "/home/username",
(A) ${1/(".*)|.*/(?1:comment => )/}
      └┤
       └ mirror of tabstop n°1, on which you perform a substitution

(B) ${1:"some comment"}
      └┤└────────────┤
       │             └ placeholder text,
       │               which fills the tabstop as long as you don't replace it
       └ tabstop n° 1


       ┌ mirror of tabstop n°1, on which you perform a substitution
      ┌┤
(C) ${1/(".*)|.*/(?1:,
    )/}home => "/home/username",

Here's a full snippet which should replicateimplement the behavior you observed in the video:

${1/(".*)|.*/(?1:comment => )/}${1:"some comment"}${1/(".*)|.*/(?1:,
)/}home => "/home/username",
(A) ${1/(".*)|.*/(?1:comment => )/}
      └┤
       └ mirror of tabstop n°1, on which you perform a substitution

(B) ${1:"some comment"}
      └┤└────────────┤
       │             └ placeholder text,
       │               which fills the tabstop as long as you don't replace it
       └ tabstop n° 1


       ┌ mirror of tabstop n°1, on which you perform a substitution
      ┌┤
(C) ${1/(".*)|.*/(?1:,
    )/}home => "/home/username",

Here's a full snippet which should replicate the behavior you observed in the video:

${1/(".*)|.*/(?1:comment => )/}${1:"some comment"}${1/(".*)|.*/(?1:,
)/}
(A) ${1/(".*)|.*/(?1:comment => )/}
      └┤
       └ mirror of tabstop n°1, on which you perform a substitution

(B) ${1:"some comment"}
      └┤└────────────┤
       │             └ placeholder text,
       │               which fills the tabstop as long as you don't replace it
       └ tabstop n° 1


       ┌ mirror of tabstop n°1, on which you perform a substitution
      ┌┤
(C) ${1/(".*)|.*/(?1:,
    )/}

Here's a full snippet which should implement the behavior you observed in the video:

added 304 characters in body
Source Link
user786441
  • 681
  • 6
  • 5

And note that the parentheses in the replacement are also important. They tell UltiSnips that it's not a literal string, but a conditional expression which must be evaluated. They are similar to the \= token which you may use in the replacement part of a substitution command in Vim (see :h :s\=).

And note that the parentheses in the replacement are also important. They tell UltiSnips that it's not a literal string, but a conditional expression which must be evaluated. They are similar to the \= token which you may use in the replacement part of a substitution command in Vim (see :h :s\=).

added 17 characters in body
Source Link
user786441
  • 681
  • 6
  • 5
Loading
added 79 characters in body
Source Link
user786441
  • 681
  • 6
  • 5
Loading
added 76 characters in body
Source Link
user786441
  • 681
  • 6
  • 5
Loading
added 4 characters in body
Source Link
user786441
  • 681
  • 6
  • 5
Loading
added 4 characters in body
Source Link
user786441
  • 681
  • 6
  • 5
Loading
Source Link
user786441
  • 681
  • 6
  • 5
Loading