3

Use vim to convert a file of markdown headings to org heading.

For example, change this:

# heading one
body
##heading two
### heading three
body

to this:

* heading one
body
**heading two
****** heading six

Only a continues sequence of '#' starting at column 0 should be substituted with an equal number of '*'.

This substitutes only the first '#' with '*':

%s/^[#]/*/c

But there can be up to six '#' to substitute.

wolfv
  • 971
  • 12
  • 20

1 Answers1

4

Use sub-string expression

%s/^#\+/\=repeat('*', len(submatch(0)))/
  • match whole of # leading a line
  • return repeated * numbered length of matched string

submatch(0) mean whole part of matched string

mattn
  • 7,571
  • 30
  • 54