honza / vim-snippets

vim-snipmate default snippets (Previously snipmate-snippets)
MIT License
4.78k stars 2.02k forks source link

sh (posix shell) snippets require $ symbols to be escaped #1381

Open seamyb88 opened 2 years ago

seamyb88 commented 2 years ago

I'm using neovim, if that's important. I'm also only talking about the SnipMate snippets.

The $ symbols which are intended to be inserted into the text need to be escaped in the snippet definitions for sh snippets.

For example in the getopt snippet, the line

echo "Usage : $${0:0} [options] [--]

should be

echo "Usage : \$${0:0} [options] [--]

and even those $ symbols which don't precede a tab stop require this also.

karangb commented 1 year ago

I'm facing a similar issue w/ PHP syntax. Let's say I have the following two snippets:

snippet foo
    $this // this was created via foo

snippet bar 
    \$this // this was created via bar

They produce:

this // this was created via foo
$this // this was created via bar

Is this expected?

smjonas commented 1 year ago

@karangb Yes that seems to be expected behavior. The snipmate docs mentions the second case but does not specify what should happen when the $ is not escaped:

Anywhere in a snippet, a backslash escapes the character following it,
regardless of whether that character is special or not. That is, '\a' will
always result in an 'a' in the output. A single backslash can be output by
using '\\'.
smjonas commented 1 year ago

Also this issue seems to be fixed in https://github.com/honza/vim-snippets/blob/master/snippets/sh.snippets and can be closed @honza @seamyb88