将此函数放在您的 vimrc 中,并根据需要使用:call VO2MD()
or 。: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