DEV Community

Pavol Z. Kutaj
Pavol Z. Kutaj

Posted on

How to Create a Markdown Code Block in Vim With a Single Keystroke

The aim of this pageđź“ť is to simplify the creation of markdown codeblock to code that is already in a file. There may be other scenarios. This is working for me. I often have a JSON in markdown or other pieces of code.

Instead of first creating the block, I paste/create the content that should go into the block, then visually select it and then press c to create the block with cursor in INSERT mode after the first triple backtick, so that I can define a language/style of the block.

  • there may be better ways just using vanilla-vim, but I just can't resist this has been my VSCODE workflow for a long time
  • therefore - select the code block visually and go with c (or whatever letter you define)
  • the implementation is simple, just put the following into your .vimrc:
  • NOTE: it is a triple backtick, not a double as shown below but it is breaking the parsing of the blog and I don't know how to escape it reliably :/
vnoremap <leader>c <esc>o``<esc>gvo<esc>O``
Enter fullscreen mode Exit fullscreen mode
  • Then select the block visually, ideally with line selection
  • Press <leader>c --> DONE

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay