Skip to content

Commit

Permalink
add: markdown helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ottijp committed Jul 14, 2024
1 parent d8a6582 commit 93206a2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions vim/ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@ function! s:MarkdownCreateLink()
call feedkeys(keys, 'n')
endfunction

" insert `*` before line
function! s:MarkdownAddListPrefix()
if mode() ==# 'v' || mode() ==# 'V' || mode() ==# "\<C-v>"
" replace all selection if it's in visual mode
execute '''<,''>s/\( \+\)\?/\1* /'
else
" repalce cursor line if it's in normal mode
execute 's/\( \+\)\?/\1* /'
endif
endfunction

" insert `[ ] ` before line
function! s:MarkdownAddCheckBox()
if mode() ==# 'v' || mode() ==# 'V' || mode() ==# "\<C-v>"
" replace all selection if it's in visual mode
execute '''<,''>s/\( \+\)\?\(* \)\?/\1\2[ ] /'
else
" repalce cursor line if it's in normal mode
execute 's/\( \+\)\?\(* \)\?/\1\2[ ] /'
endif
endfunction

" Create link with selected text and copied URL
vnoremap <buffer> <silent> <Leader>l :call <SID>MarkdownCreateLink()<CR>
" insert `*` before line
nnoremap <buffer> <silent> <Leader>* :call <SID>MarkdownAddListPrefix()<CR>
vnoremap <buffer> <silent> <Leader>* :call <SID>MarkdownAddListPrefix()<CR>
" insert `[ ] ` before line
nnoremap <buffer> <silent> <Leader>[ :call <SID>MarkdownAddCheckBox()<CR>
vnoremap <buffer> <silent> <Leader>[ :call <SID>MarkdownAddCheckBox()<CR>

0 comments on commit 93206a2

Please sign in to comment.