How to quickly create Setext headers when writing Markdown with Vim

When writing Markdown, you can define headers using the Setext style like so:

This is a header
================

If you use Vim for writing your text, you can quickly turn a line into a header with this short key combination:

yypVr=

What it does (bold text indicates the current cursor position/selection):

  1. yy yanks (copies) the current line:
    I want to be a header
  2. p pastes the yanked line below the current one and places the cursor on the first character of the pasted line
    I want to be a header
    I want to be a header
  3. V visually selects the current line (the pasted one)
    I want to be a header
    I want to be a header
  4. r= replaces every character in the current selection with the character =
    I want to be a header
    =====================

Easy, right? Another reason to love Vim! 🙂

Ăśber uns Stefan

Polyglot Clean Code Developer

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax