For example, I have text like this:
I talked to a friend, I hiked a mountain, I am working with blah blah,
And I want to delete or substitute I hiked a mountain
. Why doesn't ci,
or di,
work? Is there a way to grab, substitute, or delete between commas?
there are plugins to let you create customized text object. without installing plugins, assume your cursor is between two commas, you could do:
T,c,
or
t,c,
to simulate your ci,
for di,
change the above c
into d
related help doc:
:h t
:h T
:h ,
There are a bunch of plugins that help you create custom text-objects like textobjectify.
I've had the following snippet in my vimrc
for quite a while and it never failed me:
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
It creates all the custom operator-pending mappings required for di,
, vi%
, ci:
, ya|
and so on.
And it's easy to add new delimiters.
And I have cute smileys in my vimrc
.
If you're willing to patch Vim for this feature, there was a proposal a while back (including a mostly working patch) to allow you to match arbitrary characters. In your example it would be cim,
for "change inside matched comma". See https://groups.google.com/d/topic/vim_dev/pZxLAAXxk0M/discussion for the discussion and a few versions of the patch. I've been using it a long time and the only problem I've encountered is in visual mode; but then again, I don't use the feature as often as I expected to.
If you are in a section like that you could use T,ct,
.
Or you if you want to install a plugin like vim-argumentative allows you to use ci,
and di,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With