" Markdown Header Mappings - Easy setting of markdown headers "------------------------------------------------------------ function! s:SmartLevelFourHeader() call s:DeleteExistingUnderline() call s:DeleteExistingLeadingHeaderMarks() s/^/#### / silent! call repeat#set("\SmartLevelFourHeader") endfunction function! s:SmartLevelThreeHeader() call s:DeleteExistingUnderline() call s:DeleteExistingLeadingHeaderMarks() s/^/### / silent! call repeat#set("\SmartLevelThreeHeader") endfunction function! s:OnLastLineOfFile() return line('.') == line('$') endfunction function! s:DeleteExistingLeadingHeaderMarks() silent! s/^#\{1,6} // endfunction function! s:DeleteExistingUnderline() if !s:OnLastLineOfFile() let saved_cursor = getpos(".") +1g/\v^[-=]+$/d call setpos('.', saved_cursor) endif endfunction function! s:SmartUnderline(char) call s:DeleteExistingUnderline() call s:DeleteExistingLeadingHeaderMarks() let underline = repeat(a:char, len(getline('.'))) call append(line('.'), underline) if a:char == '=' silent! call repeat#set("\UnderlineH1", v:count) else silent! call repeat#set("\UnderlineH2", v:count) end endfunction nnoremap UnderlineH1 :call SmartUnderline('=') nnoremap UnderlineH2 :call SmartUnderline('-') nnoremap SmartLevelThreeHeader :call SmartLevelThreeHeader() nnoremap SmartLevelFourHeader :call SmartLevelFourHeader() nmap u1 UnderlineH1 nmap u2 UnderlineH2 nmap u3 SmartLevelThreeHeader nmap u4 SmartLevelFourHeader " vim:ft=vim