From 6fa2b683bd69d402056981b43bd1aa8d1ae68d63 Mon Sep 17 00:00:00 2001 From: David Vezzani Date: Fri, 25 Sep 2015 11:04:01 -0700 Subject: [PATCH] adds MdMakeCodeBlock: qc - visual mode; highlight region first adds MdMakeUnorderedList: qlu - make sure that there is a blank newline after block adds MdMakeOrderedList: qlo - make sure that there is a blank newline after block adds MdMakeBold: qb - put cursor any place on line changes MdFixOrderedList: qlf - renames shortcut so qlu and qlo can be used --- ftplugin/md.vim | 61 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) 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 %