aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md15
-rw-r--r--VERSION1
-rw-r--r--autoload/clear_local_maps.vim44
-rw-r--r--doc/clear_local_maps.txt38
4 files changed, 98 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c14e748
--- /dev/null
+++ b/README.md
@@ -0,0 +1,15 @@
+clear\_local\_maps.vim
+======================
+
+This plugin provides an autoload function that clears all buffer-local mappings
+that begin with `maplocalleader`. It's intended for use at the start of an
+`augroup` that sets up filetype mappings, to clear away existing ones in the
+buffer first.
+
+License
+-------
+
+Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself.
+See `:help license`.
+
+[1]: https://sanctum.geek.nz/
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0
diff --git a/autoload/clear_local_maps.vim b/autoload/clear_local_maps.vim
new file mode 100644
index 0000000..1668dfb
--- /dev/null
+++ b/autoload/clear_local_maps.vim
@@ -0,0 +1,44 @@
+" Get all buffer-local mappings into a string variable
+function! clear_local_maps#GetBufferLocalMaps() abort
+ redir => l:out
+ map <buffer>
+ redir END
+ let g:clear_local_maps#buffer_local_maps = l:out
+endfunction
+
+" Clear all buffer-local mappings beginning with <LocalLeader>
+function! clear_local_maps#ClearBufferLocalLeaderMaps() abort
+
+ " Do nothing if there isn't a defined local leader
+ if !exists('g:maplocalleader')
+ return
+ endif
+
+ " Get all the buffer-local mappings into a list
+ silent call clear_local_maps#GetBufferLocalMaps()
+ let l:mappings = split(g:clear_local_maps#buffer_local_maps, '\n')
+
+ " Iterate through the mappings
+ for l:mapping in l:mappings
+
+ " Match the list mapping and mode; skip if no match
+ let l:matchlist = matchlist(l:mapping, '\m\C^\(.\)\s\+\(\S\+\)')
+ if !len(l:matchlist)
+ continue
+ endif
+ let l:mode = l:matchlist[1]
+ let l:sequence = l:matchlist[2]
+
+ " If the mapping starts with our local leader, clear it
+ if stridx(l:sequence, g:maplocalleader) == 0
+ execute l:mode.'unmap <buffer> '.l:sequence
+ endif
+
+ endfor
+
+endfunction
+
+" Wrapper around ClearLocalMaps with a shorter name
+function! clear_local_maps#Clear() abort
+ call clear_local_maps#ClearBufferLocalLeaderMaps()
+endfunction
diff --git a/doc/clear_local_maps.txt b/doc/clear_local_maps.txt
new file mode 100644
index 0000000..f53ffb0
--- /dev/null
+++ b/doc/clear_local_maps.txt
@@ -0,0 +1,38 @@
+*clear_local_maps.txt* For Vim version 7.0 Last change: 2018 June 25
+
+DESCRIPTION *clear_local_maps*
+
+This plugin provides an autoload function that clears all buffer-local mappings
+that begin with |maplocalleader|. It's intended for use at the start of an
+|augroup| that sets up filetype mappings, to clear away existing ones in the
+buffer first.
+
+REQUIREMENTS *clear_local_maps-requirements*
+
+This plugin is only available if 'compatible' is not set. It also requires the
+|+autocmd| feature.
+
+FUNCTIONS *clear_local_maps-functions*
+ *clear_local_maps#Clear()*
+The autoloaded function `clear_local_maps#Clear()` examines the list of
+|map-local| mappings and clears any that begin with `g:maplocalleader`. If
+`g:maplocalleader` is unset, it does nothing.
+
+You might use it in your |vimrc| like this:
+>
+ let g:maplocalleader = '_'
+ augroup vimrc_filetype_mappings
+ autocmd!
+ autocmd FileType * call clear_local_maps#Clear()
+ " Filetype-local mappings go here...
+ augroup END
+<
+AUTHOR *clear_local_maps-author*
+
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
+
+LICENSE *clear_local_maps-license*
+
+Licensed for distribution under the same terms as Vim itself (see |license|).
+
+ vim:tw=78:ts=8:ft=help:norl: