3

VimOutlinerファイルをMarkdownに変換するにはどうすればよいですか?言い換えれば、私はこのようなタブに依存するアウトラインをどのように変えるか...

Heading 1
    Heading 2
            Heading 3
            : Body text is separated by colons.
            : Another line of body text.
    Heading 4

...次のように空の行で区切られたハッシュスタイルの見出しに:

# Heading 1

## Heading 2

### Heading 3

Body text.

## Heading 4

私はマクロを定義しようとしましたが、Vim(コーダーではない)にかなり慣れていないので、これまでのところ成功していません。助けてくれてありがとう!

(PS-Markdownに関しては、すばらしいVOoMプラグインについては知っていますが、ハッシュ文字が表示されていないドキュメントの初期アウトラインを作成することを好みます。さらに、VimOutlinerがさまざまなレベルの見出しを強調表示する方法も気に入っています。)

4

1 に答える 1

4

この関数をvimrcに配置し、必要に応じて:call VO2MD()または:call MD2VO()必要に応じて使用します。

function! VO2MD()
  let lines = []
  let was_body = 0
  for line in getline(1,'$')
    if line =~ '^\t*[^:\t]'
      let indent_level = len(matchstr(line, '^\t*'))
      if was_body " <= remove this line to have body lines separated
        call add(lines, '')
      endif " <= remove this line to have body lines separated
      call add(lines, substitute(line, '^\(\t*\)\([^:\t].*\)', '\=repeat("#", indent_level + 1)." ".submatch(2)', ''))
      call add(lines, '')
      let was_body = 0
    else
      call add(lines, substitute(line, '^\t*: ', '', ''))
      let was_body = 1
    endif
  endfor
  silent %d _
  call setline(1, lines)
endfunction

function! MD2VO()
  let lines = []
  for line in getline(1,'$')
    if line =~ '^\s*$'
      continue
    endif
    if line =~ '^#\+'
      let indent_level = len(matchstr(line, '^#\+')) - 1
      call add(lines, substitute(line, '^#\(#*\) ', repeat("\<Tab>", indent_level), ''))
    else
      call add(lines, substitute(line, '^', repeat("\<Tab>", indent_level) . ': ', ''))
    endif
  endfor
  silent %d _
  call setline(1, lines)
endfunction
于 2012-03-23T16:01:18.067 に答える