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

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants
@t9md

t9md commented Jul 16, 2011

introduce g:surround_custom_mapping dictionary which help filetype based custom mapping.

I hope this mini utility for surround.vim is bundled in orignal surround.vim.
User can easily add custom mapping rule for each &filetype or global scope based.

configuration example

let g:surround_custom_mapping = {}"{{{
let g:surround_custom_mapping._ = {
            \ 'p':  "<pre> \r </pre>",
            \ 'w':  "%w(\r)",
            \ }
let g:surround_custom_mapping.help = {
            \ 'p':  "> \r <",
            \ }
let g:surround_custom_mapping.ruby = {
            \ '-':  "<% \r %>",
            \ '=':  "<%= \r %>",
            \ '9':  "(\r)",
            \ '5':  "%(\r)",
            \ '%':  "%(\r)",
            \ 'w':  "%w(\r)",
            \ '#':  "#{\r}",
            \ '3':  "#{\r}",
            \ 'e':  "begin \r end",
            \ 'E':  "<<EOS \r EOS",
            \ 'i':  "if \1if\1 \r end",
            \ 'u':  "unless \1unless\1 \r end",
            \ 'c':  "class \1class\1 \r end",
            \ 'm':  "module \1module\1 \r end",
            \ 'd':  "def \1def\1\2args\r..*\r(&)\2 \r end",
            \ 'p':  "\1method\1 do \2args\r..*\r|&| \2\r end",
            \ 'P':  "\1method\1 {\2args\r..*\r|&|\2 \r }",
            \ }
let g:surround_custom_mapping.javascript = {
            \ 'f':  "function(){ \r }"
            \ }
let g:surround_custom_mapping.lua = {
            \ 'f':  "function(){ \r }"
            \ }
let g:surround_custom_mapping.python = {
            \ 'p':  "print( \r)",
            \ '[':  "[\r]",
            \ }
let g:surround_custom_mapping.vim= {
            \'f':  "function! \r endfunction"
            \ }
@graywh

This comment has been minimized.

Show comment
Hide comment
@graywh

graywh Jul 18, 2011

This is already possible with global and buffer-local variables.

graywh commented Jul 18, 2011

This is already possible with global and buffer-local variables.

@t9md

This comment has been minimized.

Show comment
Hide comment
@t9md

t9md Jul 18, 2011

graywh , I know that, I use it's global and buffer-local variables.

The purpose of my change is that user don't need to use char2nr and user can use dictonary to define filetype specific custom mapping.
In Filetype autocmd dictonary value for &filetype is processed to define custome mapping.

t9md commented Jul 18, 2011

graywh , I know that, I use it's global and buffer-local variables.

The purpose of my change is that user don't need to use char2nr and user can use dictonary to define filetype specific custom mapping.
In Filetype autocmd dictonary value for &filetype is processed to define custome mapping.

@tpope

This comment has been minimized.

Show comment
Hide comment
@tpope

tpope Aug 7, 2011

Owner

Back when I first wrote surround.vim, Vim 7 was new and Vim 6 was still commonly provided with OS distributions. I strove to make surround.vim strictly backwards compatible (even though this meant only a subset of the functionality worked) so that I could still make use of it on servers an whatnot. Those days are long behind us, so for a while now I've had ambitious plans which included a hash like syntax for customization.

A couple of differences in my vision:

  • Instead of merely wrapping the old interface (and mapping the hash to variables), I want it to be first class. You should be able to modify the hash and have surroundings show up instantly.
  • I'd rather have per-buffer hashes than per-filetype hashes, as their a bit more flexible. If I do add the latter, it will leverage the former.

Now that I'm finally getting on top of my open source stuff, hopefully you'll see progress on this in the next month or two. I'll leave the pull request open until then.

Owner

tpope commented Aug 7, 2011

Back when I first wrote surround.vim, Vim 7 was new and Vim 6 was still commonly provided with OS distributions. I strove to make surround.vim strictly backwards compatible (even though this meant only a subset of the functionality worked) so that I could still make use of it on servers an whatnot. Those days are long behind us, so for a while now I've had ambitious plans which included a hash like syntax for customization.

A couple of differences in my vision:

  • Instead of merely wrapping the old interface (and mapping the hash to variables), I want it to be first class. You should be able to modify the hash and have surroundings show up instantly.
  • I'd rather have per-buffer hashes than per-filetype hashes, as their a bit more flexible. If I do add the latter, it will leverage the former.

Now that I'm finally getting on top of my open source stuff, hopefully you'll see progress on this in the next month or two. I'll leave the pull request open until then.

@t9md

This comment has been minimized.

Show comment
Hide comment
@t9md

t9md Aug 7, 2011

I'm happy to hear your ambitious plan to support hash like customization.
I'm looking forward to see your new version of surround.vim!!
Thanks.

t9md commented Aug 7, 2011

I'm happy to hear your ambitious plan to support hash like customization.
I'm looking forward to see your new version of surround.vim!!
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment