aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/vimrc.vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-06-25 14:01:59 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-06-25 14:01:59 +1200
commit4195ce53f3454c1ed5b85bd29fa75af84d3c455f (patch)
tree94461e8de93db0da5557fff3638278fb759043d6 /vim/autoload/vimrc.vim
parentMerge branch 'release/v1.2.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-1.3.0.tar.gz (sig)
dotfiles-1.3.0.zip
Merge branch 'release/v1.3.0'v1.3.0
* release/v1.3.0: Bump VERSION Clear local leader maps on filetype change Upgrade fixed_join.vim, define map explicitly Remove misguided buffer mapping clear
Diffstat (limited to 'vim/autoload/vimrc.vim')
-rw-r--r--vim/autoload/vimrc.vim39
1 files changed, 39 insertions, 0 deletions
diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim
new file mode 100644
index 00000000..eaeefd5d
--- /dev/null
+++ b/vim/autoload/vimrc.vim
@@ -0,0 +1,39 @@
+" Get all buffer-local mappings into a string variable
+function! vimrc#GetBufferLocalMaps() abort
+ redir => l:out
+ map <buffer>
+ redir END
+ let g:vimrc#buffer_local_maps = l:out
+endfunction
+
+" Clear all buffer-local mappings beginning with <LocalLeader>
+function! vimrc#ClearLocalLeaderMaps() 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 vimrc#GetBufferLocalMaps()
+ let l:mappings = split(g:vimrc#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