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

[question] aliases for quoter and brackets? #103

Closed
alex-popov-tech opened this issue Aug 21, 2020 · 6 comments
Closed

[question] aliases for quoter and brackets? #103

alex-popov-tech opened this issue Aug 21, 2020 · 6 comments

Comments

@alex-popov-tech
Copy link

alex-popov-tech commented Aug 21, 2020

Hey, thanks for a great plugin!
Question - I could not figured out how to create aliases for different kind of pair characters, could you please help to build/add instruction to readme/add them by default?

Example:

  • q for any kind of quotes (' " `), so '"ke|k"' -> srq` -> '`ke|k`'
  • b for any kind of brackets ( [ ( { ), so ([ke|k]) -> srb{ -> ({ke|k})
@garymh
Copy link

garymh commented Jan 3, 2021

Looking for this as well 😄

@tuxflo
Copy link

tuxflo commented Aug 12, 2021

Me too, I'm already using targets.vim so ciq is stuck in my muscle memory.

@singlexyz
Copy link

singlexyz commented Mar 31, 2022

The sandwich can automatically select the corresponding text according to your recipes, the key is b.
https://github.com/machakann/vim-sandwich#textobj-sandwich

If you have special needs, you can customize a recipe with regexp, like:

let g:sandwich#recipes = deepcopy(g:sandwich#default_recipes)
let g:sandwich#recipes += [
      \   {
      \     'buns': ["[`'\"]\s*", "\s*[`'\"]"],
      \     'input'   : ['q'],
      \     'regex': 1,
      \   },
      \ ]

@machakann
Copy link
Owner

See #145

@astier
Copy link

astier commented Mar 4, 2023

For people who use target.vim and want to use its builtin objects like q the following solution seems to work which was discussed in #92

let g:textobj_sandwich_no_default_key_mappings = 1
let g:sandwich_no_default_key_mappings = 1
nmap sa <plug>(operator-sandwich-add)
xmap sa <plug>(operator-sandwich-add)
nmap sd <plug>(operator-sandwich-delete)a
nmap sr <plug>(operator-sandwich-replace)a

It has the additional benefit that for example sr( would search for the next match on line if the cursor is not within surrounding.
Not sure if this solution has any unwanted side-effects.

@astier
Copy link

astier commented Mar 7, 2023

Sadly it seems to break the magic character f. To make it work I had to add additionally:

nmap sdf <plug>(sandwich-delete)f
nmap srf <plug>(sandwich-replace)f

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

No branches or pull requests

6 participants