0

I use Ultisnips in vim a lot together with vim-expand:

snippet prg 
!This is file : `!v expand('%:r')`
! Author= `!v expand($USER)`
! Started at: `date +%d.%m.%y`
! 
Program  ${1:`!v expand('%:r')`}
Implicit None
${2:<++Start Typing++>}
End Program  $1
endsnippet

I am facing a problem that, after the ${1:} is expanded in ${1:`!v expand('%:r')`}, if I put a linebreak, the $1 in End Program $1 is picking that up as well; which in NOT intended. To make it clear, here is a screencast: https://www.youtube.com/watch?v=0IjoqWXQNI8

I want to expand and match the first line, but not after linebreak. kindly help.

BaRud
  • 3,055
  • 7
  • 41
  • 89

1 Answers1

0

What you are looking for is something already covered by the screencast for Ultisnips. All you need is regex adjustment to your snippet value $1

Program  ${1:`!v expand('%:r')`}
Implicit None
${2:<++Start Typing++>}
End Program  ${1/([^\n$]+).*/$1/}
endsnippet

${1/([^\n$]+).*/$1/}
        |     |  |
        |     |  +--------Replace by first atom i.e. Matched by (..)
        |     +--------Anything That follows.
        +----------- Match everything except a newline | EOL(endofline)
DOOM
  • 1,170
  • 6
  • 20