From: Ciro Santilli 六四事件 法轮功 Date: Mon, 4 May 2015 14:14:30 +0000 (+0200) Subject: Allow users to disable individual maps with hasmapto checks X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/21e96cbe9b8e6ea61b11709fff11e4d42a82ce16?ds=sidebyside;hp=-c Allow users to disable individual maps with hasmapto checks --- 21e96cbe9b8e6ea61b11709fff11e4d42a82ce16 diff --git a/README.md b/README.md index 5ba457d..894037a 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,14 @@ The following work on normal and visual modes: - `]u`: go to parent header (Up). `Markdown_MoveToParentHeader` +This plugging follows the recommended Vim plugin mapping interface, so if you want to change the map `]u` to `asdf`, add to your `.vimrc`: + + map asdf Markdown_MoveToParentHeader + +To disable a map, use: + + map Markdown_MoveToParentHeader + ## Commands - `:HeaderDecrease`: diff --git a/ftplugin/mkd.vim b/ftplugin/mkd.vim index 6e04bd2..d67864a 100644 --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@ -510,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') @@ -519,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(, )