machakann / vim-sandwich

Set of operators and textobjects to search/select/edit sandwiched texts.
1.44k stars 37 forks source link

How do you write recipe for all quotes types + miscellaneous characters? #139

Closed ckangnz closed 2 years ago

ckangnz commented 2 years ago

I'm using vim-surround mapping.

I would like to implement something like

viq ciq diq caq daq csq dsq mapping to change or delete any quote marks including ' " or backtick.

*** I don't mind about ysiwq as it won't know which quote i mean.

Example : "'Text'"

I was searching through the web and the doc but all I could find was this example:

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

However, the above example doesn't work as intended.

I think the documentation should have a few more examples on how to implement simple mappings (for example q in this case) to whatever you would like to surround with.

Also I have had this in my .vimrc for a long time, and now since vim-sandwich allows customising, I wanted to implement this in input of a.

for char in [ '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '-', '#' ]
    execute 'xnoremap i' . char . ' :<C-u>normal! T' . char . 'vt' . char . '<CR>'
    execute 'onoremap i' . char . ' :normal vi' . char . '<CR>'
    execute 'xnoremap a' . char . ' :<C-u>normal! F' . char . 'vf' . char . '<CR>'
    execute 'onoremap a' . char . ' :normal va' . char . '<CR>'
endfor

Basically, I would like to have similar functionality (e.g. cia dia csa dsa etc.) to recognise all of '_', '.', ':', ',', ';', '<bar>', '/', '<bslash>', '*', '+', '-', '#' as a. (Or anything else like o or x or whatever)

For example : THIS_IS_A|_NAME (cursor represented as |)

What would be the simplest way to implement these?

machakann commented 2 years ago

See #145