I am trying to make it so I can have a keymap for toggling things like bold in a markdown file.
I used to use vscode with the markdown plugin and they offered the option to, with a simple keybind, toggle on or off the bold on a specific word by adding two asterisks on each side of the word. If the cursor wasn't on top of a word, the four asterisks would be written and the cursor placed inside ready to write what I would like in bold.

In neovim I didn't find any plugin with this capability so I just thought about writing my own keybind for that.

The problem I found was detecting if the word was already with bold active or not. I could make two different keymaps, but wouldn't be what I was looking for.

Is there a good way of doing this?

Thank you:)

1 Answer 1


I usually use surround.vim for this. You could do

nmap <buffer> <your keys> ysiw*
nmap <buffer> <more keys> ds*

In ~/.vim/after/ftplugin/markdown.vim or equivalent. Make sure to adjust b:undo_ftplugin.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.