5

How would you surround the following text with 3 backticks ``` using tpope's Vim Surround.

All I can is 1 backtick using S` in visual mode:

enter image description here

Mick
  • 30,759
  • 16
  • 111
  • 130

3 Answers3

9

This is not what you asked but this can be done without surround:

(from visual mode)
c
```
<C-r>"
```
<Esc>

See :help ctrl-r.

romainl
  • 186,200
  • 21
  • 280
  • 313
4

Define a custom surround:

(Insert following in your .vimrc or file specific config ~/.vim/after/ftplugin/markdown.vim )

" Custom surrounds
let b:surround_{char2nr('c')} = "```\r```"

now visual select and Sc will give you desired surround.

Or use a snippet solution; for example using Ultisnips define a snippet like so:

snippet code
\`\`\`${1}
${0:${VISUAL}}
\`\`\`
endsnippet

now visual select your desired lines then hit snippet expansion key ( mine is Tab ) type code and hit Tab again. that's it.

dNitro
  • 5,145
  • 2
  • 20
  • 45
  • Nice one @dNitro - Will accept this as this is using Vim Surround. Though romainl answer was really good tool – Mick Nov 21 '17 at 01:08
2

Here another ultisnips solution.

snippet code "add backtics codes" w
`!v repeat(nr2char(96),3)` ${1:markdown}
${0:${VISUAL:type here}}
`!v repeat(nr2char(96),3)`
endsnippet

If you do not want "markdown" after the first line just get rid of it. I am showing this solution only to show how to avoid backslashing so much.

SergioAraujo
  • 11,069
  • 3
  • 50
  • 40