From 1e3cf934a276793ca782d16c71d1e5a4fe3819c8 Mon Sep 17 00:00:00 2001 From: t9md Date: Sat, 16 Jul 2011 22:51:20 +0900 Subject: [PATCH 1/2] introduce g:surround_custom_mapping dictionary which help filetype based custom mapping. --- plugin/surround.vim | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugin/surround.vim b/plugin/surround.vim index 8028990..79150fa 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -621,6 +621,30 @@ if !exists("g:surround_no_mappings") || ! g:surround_no_mappings "imap ISurround endif +if !exists('g:surround_custom_mapping') + let g:surround_custom_mapping = {} +endif + +function! s:surround_custom_map(scope) "{{{ + if (a:scope != 'g') && empty(&ft) + return + endif + let map_dict = a:scope == 'g' ? 'global' : &ft + + if !has_key(g:surround_custom_mapping, map_dict) + return + end + for [key, action] in items(g:surround_custom_mapping[map_dict]) + let command = "let ".a:scope.":surround_".char2nr(key)." = ".string(action) + execute command + endfor +endfunction"}}} +augroup Surround + autocmd! + autocmd VimEnter * call s:surround_custom_map('g') + autocmd FileType * call s:surround_custom_map('b') +augroup END + let &cpo = s:cpo_save " vim:set ft=vim sw=2 sts=2 et: From 5b1391752d6b4d63464ff40ab95dc575eb504104 Mon Sep 17 00:00:00 2001 From: t9md Date: Sat, 16 Jul 2011 23:10:10 +0900 Subject: [PATCH 2/2] I notice key 'global' for global mapping is not good, possibly conflict in future. so user `_` as key for global mapping --- plugin/surround.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/surround.vim b/plugin/surround.vim index 79150fa..e46a9ac 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -629,7 +629,7 @@ function! s:surround_custom_map(scope) "{{{ if (a:scope != 'g') && empty(&ft) return endif - let map_dict = a:scope == 'g' ? 'global' : &ft + let map_dict = a:scope == 'g' ? '_' : &ft if !has_key(g:surround_custom_mapping, map_dict) return