How to remove or snatch inside slashes and stars?

I use di" for quotes di{ for brackets and dit for HTML tags.

I often work with CSS. I want to remove slashes or asterisks inside. For instance:

 /* This is a comment. Delete or yank me. ;) */ .button { content: 'Change my comment.'; } 

I do not want to do this with functions, etc. How do I match these keywords with all variations? (Especially I need delete inside , yank inside , delete around , delete and go insert mode (ci/) ) For example:

 di/ yi/ ci/ ya/ da/ di* ya* 

etc...

+5
source share
2 answers

You can define your own text objects by combining visual mode display and standby mapping.

This snippet will create the text object i/ :

 xnoremap i/ :<Cu>normal! T/vt/<CR> onoremap i/ :normal vi/<CR> 

which you can use as built-in: ci/ , vi/ , di/ , yi/ .

And this will create a text object a/ :

 xnoremap a/ :<Cu>normal! F/vf/<CR> onoremap a/ :normal va/<CR> 

which you can use as built-in: ca/ , va/ , da/ , ya/ .


BONUS: This is an easily extensible snippet from my vimrc that creates at least 26 new text objects, including the ones you want:

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

There is also an excellent targets.vim plugin that includes those text objects and a huge number of others. It might be worth checking out, especially if you don't want to define your own.

+4
source

Source: https://habr.com/ru/post/1268090/


All Articles