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

Conversation

t9md
Copy link

@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
Copy link

graywh commented Jul 18, 2011

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

@t9md
Copy link
Author

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
Copy link
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
Copy link
Author

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.

halostatue added a commit to halostatue/vim9-surround that referenced this pull request Aug 6, 2024
This implements surround mapping definition as maps.

Related-to: tpope#32
halostatue added a commit to halostatue/vim9-surround that referenced this pull request Aug 8, 2024
This implements surround mapping definition as maps.

Related-to: tpope#32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants