On , I learnt ...

How to create custom replacements for vim-surround

Problem

I forgot my notepad and was editing a todo.md buffer in Vim as a replacement checklist.

Rather than deleting completed lines, I wanted to wrap them in ~~ to strike them out (so I could remember what I had done that day).

This was awkward as vim-surround doesn’t have a default mapping for ~~.

Solution

Define a custom replacement for Markdown-filetype buffers:

" ~/.vim/after/ftplugin/markdown.vim
let b:surround_{char2nr('s')} = "~~\r~~"

Now s can be used to surround text with ~~ in Markdown buffers. Example usage:

See the vim-surround help documentation for more details on customisation.