Blog 1

Random Talk on Random Thoughts

Indentation of Titles in Markdown Files in Vim

| Comments |

Background

While I was writing a post about a technical problem encountered while writing another post about Venn diagram, I encountered another technical problem.

Problem

I tried including the error message into the previous post by the Vim editor command :r ~/lang:text temp-swp.mkd. To have it surrounded with <pre><code> in HTML, one needs to indent it by four spaces.

A section of the error message (temp-swp.mkd) download
1
2
3
4
5
6
7
8
## Generating Site with Jekyll
    write source/stylesheets/screen.css
Configuration file: /home/owner/octopress/_config.yml
            Source: source
       Destination: public
      Generating...
                    done.
 Auto-regeneration: disabled. Use --watch to enable.

I usally do this by applying the right-shift operator > to the text selected in visual line mode. However, the line starting with # wasn’t indented like the others.

A failed indentation (temp-swp1.mkd) download
1
2
3
4
5
6
7
8
## Generating Site with Jekyll
        write source/stylesheets/screen.css
    Configuration file: /home/owner/octopress/_config.yml
                Source: source
           Destination: public
          Generating...
                        done.
     Auto-regeneration: disabled. Use --watch to enable.

Discussion

If I started Vim with all plugins disabled with vim -u NONE -N, then the above problem won’t happen.

Solution

Use the visual block mode instead. Either one way will do.

  1. Keep using the > operator.
  2. Use I instead of >.

Comments