3

I wanna write a snippet like this:

snippet code
    ``` ${1:ruby}

    ```

but `` is used to wrap script command, how could I make it?

Thanks all !

2
  • please tell me you tried escaping them with \ first Commented Feb 22, 2013 at 5:26
  • @AndyRay yes, I tried it, doesn't work , so I asked it here!! Commented Feb 22, 2013 at 5:48

3 Answers 3

3

Newer versions of snipMate allow for escaping backticks:


snippet code
    \`\`\` ${1:ruby}

    \`\`\`

https://github.com/garbas/vim-snipmate

https://github.com/msanders/snipmate.vim

Sign up to request clarification or add additional context in comments.

Comments

2

You should have mentioned which snippet plugin you're using. I'm assuming the original snipMate, because that one doesn't handle escaped backticks.

You can work around this with a Vim expression which yields the backtick:

snippet backtick
    `!v nr2char(96)`

In your case, I would use

snippet code
    `!v repeat(nr2char(96),3)` ${1:ruby}

    `!v repeat(nr2char(96),3)`

4 Comments

Thanks first, yes, I use snipMate plugin, I have tested the repeat(nr2char(96),3) in vim, my code is :echo repeat(nr2char(96),3), it worked but When I added your code in my markdown.snippets without the echo,and adjust indents, it comes out invalid expression
Oh, sorry; I'm using a personal fork, this might not work in the original plugin. I've done some more research; see my other answer.
@user2031771: My answer was for the original snipMate, the !v added by your edit presumably is extended UltiSnips syntax, right?! I don't mind the edit; users should figure this out, and probably UltiSnips is more commonplace by now.
If you are using ultisnips you also need endsnippet at the end of snippet
0

The original snipMate as found on vim.org in version 0.83 doesn't allow escaping of backticks. However, version 0.84 in the abandoned repository seems to have it (cp. commit b2937829). It might be worth a try.

Alternatively, I have separately added that enhancement to my personal fork; unfortunately, it's mixed in there with many customizations and stuff that will not suit you. (But you could theoretically extract a patch from the list of commits.)

Maybe it's best to move to another, more modern and maintained snippet plugin. UltiSnips - The ultimate snippet solution for python enabled Vim is currently en vogue (but requires Python support).

1 Comment

Thanks a lot, I have python env, and I will try UltiSnips

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.