From 21e96cbe9b8e6ea61b11709fff11e4d42a82ce16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?utf8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Mon, 4 May 2015 16:14:30 +0200 Subject: [PATCH] Allow users to disable individual maps with hasmapto checks --- README.md | 8 ++++++++ ftplugin/mkd.vim | 28 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) 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(, ) -- 2.39.5