Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dictionary for user can add custom mapping rule. #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions plugin/surround.vim
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,30 @@ if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
"imap <C-S><C-S> <Plug>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' ? '_' : &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: