X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/f3c4ace059796ff87802aa0d20732965bb8c8a32..314f86e7a11e5e90eb49a795c29b807ceb46fe6c:/ftplugin/mkd.vim?ds=sidebyside diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index 05316ab..d67864a 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -464,14 +464,12 @@ endfunction " - a string with the the URL for the link under the cursor " - an empty string if the cursor is not on a link " -" `b:` instead of `s:` to make it testable. -" " TODO " " - multiline support " - give an error if the separator does is not on a link " -function! b:Markdown_GetUrlForPosition(lnum, col) +function! s:Markdown_GetUrlForPosition(lnum, col) let l:lnum = a:lnum let l:col = a:col let l:syn = synIDattr(synID(l:lnum, l:col, 1), 'name') @@ -504,7 +502,7 @@ endfunction " Front end for GetUrlForPosition. " function! s:OpenUrlUnderCursor() - let l:url = b:Markdown_GetUrlForPosition(line('.'), col('.')) + let l:url = s:Markdown_GetUrlForPosition(line('.'), col('.')) if l:url != '' call netrw#NetrwBrowseX(l:url, 0) else @@ -512,6 +510,13 @@ function! s:OpenUrlUnderCursor() endif endfunction +function! s:MapNotHasmapto(lhs, rhs) + if !hasmapto('' . a:rhs) + execute 'nmap ' . a:lhs . ' ' . a:rhs + execute 'vmap ' . a:lhs . ' ' . a:rhs + endif +endfunction + call MapNormVis('Markdown_MoveToNextHeader', 'MoveToNextHeader') call MapNormVis('Markdown_MoveToPreviousHeader', 'MoveToPreviousHeader') call MapNormVis('Markdown_MoveToNextSiblingHeader', 'MoveToNextSiblingHeader') @@ -521,20 +526,13 @@ call MapNormVis('Markdown_MoveToCurHeader', 'MoveToCurHeader') nnoremap Markdown_OpenUrlUnderCursor :call OpenUrlUnderCursor() if !get(g:, 'vim_markdown_no_default_key_mappings', 0) - nmap ]] Markdown_MoveToNextHeader - nmap [[ Markdown_MoveToPreviousHeader - nmap ][ Markdown_MoveToNextSiblingHeader - nmap [] Markdown_MoveToPreviousSiblingHeader - nmap ]u Markdown_MoveToParentHeader - nmap ]c Markdown_MoveToCurHeader - nmap gx Markdown_OpenUrlUnderCursor - - vmap ]] Markdown_MoveToNextHeader - vmap [[ Markdown_MoveToPreviousHeader - vmap ][ Markdown_MoveToNextSiblingHeader - vmap [] Markdown_MoveToPreviousSiblingHeader - vmap ]u Markdown_MoveToParentHeader - vmap ]c Markdown_MoveToCurHeader + call MapNotHasmapto(']]', 'Markdown_MoveToNextHeader') + call MapNotHasmapto('[[', 'Markdown_MoveToPreviousHeader') + call MapNotHasmapto('][', 'Markdown_MoveToNextSiblingHeader') + call MapNotHasmapto('[]', 'Markdown_MoveToPreviousSiblingHeader') + call MapNotHasmapto(']u', 'Markdown_MoveToParentHeader') + call MapNotHasmapto(']c', 'Markdown_MoveToCurHeader') + call MapNotHasmapto('gx', 'Markdown_OpenUrlUnderCursor') endif command! -buffer -range=% HeaderDecrease call s:HeaderDecrease(, )