diff --git a/ftplugin/md.vim b/ftplugin/md.vim index 4239382..46f1b72 100644 --- a/ftplugin/md.vim +++ b/ftplugin/md.vim @@ -20,8 +20,61 @@ function! MdMakeHeader(character) endif endfunction -function! MdFixOrderedList() +function! MdMakeBold() + echo "" + call MdMarkLine('**') +endfunction + +function! MdMarkLine(character) + let line = substitute(getline("."), "\\s\\+$", "", "") + let newLine = substitute(line, ".*", a:character.'\0'.a:character, "") + call setline(".", newLine) +endfunction + +function! MdMakeCodeBlock() + echo "" + let z = '`>' | normal @z + let lastLine = line(".") + let z = '`<^' | normal @z + + let line = line(".") + while line > lastLine + let newLine = substitute(getline(line), ".*", ' \0', "") + call setline(line, newLine) + + let line = line + 1 + endwhile + + let newLine = substitute(getline(line), ".*", ' \0', "") + call setline(line, newLine) +endfunction + +function! MdMakeUnorderedList() + echo "" + let line = line(".") + while getline(line) !~ "^\\s*$" + let newLine = substitute(getline(line), ".*", '* \0', "") + call setline(line, newLine) + + let line = line + 1 + endwhile +endfunction + +function! MdMakeOrderedList() echo "" + let cnt = 1 + let line = line(".") + while getline(line) !~ "^\\s*$" + let newLine = substitute(getline(line), ".*", cnt.'. \0', "") + call setline(line, newLine) + + let cnt = cnt + 1 + let line = line + 1 + endwhile +endfunction + +function! MdFixOrderedList() + echo "asdf" let ltop = line(".") while getline(ltop) =~ "^\\s*[0-9]\\+\\." || \ (getline(ltop) =~ "^\\s" && getline(ltop) !~ "^\\s*$") @@ -102,9 +155,13 @@ function! MdFold() endfunction " Shortcuts +vmap qc :call MdMakeCodeBlock() +nmap qlu :call MdMakeUnorderedList() +nmap qlo :call MdMakeOrderedList() +nmap qb :call MdMakeBold() nmap q= :call MdMakeH1() nmap q- :call MdMakeH2() -nmap ql :call MdFixOrderedList() +nmap qlf :call MdFixOrderedList() nmap qz :call MdFold() nmap qp :!mdprev % nmap qP :!mdprev --pdf %