Can you substitute or delete between commas (or any arbitrary character) in vi/vim?

后端 未结 4 876
日久生厌
日久生厌 2021-02-04 16:21

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

4条回答
  •  清酒与你
    2021-02-04 17:03

    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 [ '_', '.', ':', ',', ';', '', '/', '', '*', '+', '%' ]
      execute 'xnoremap i' . char . ' :normal! T' . char . 'vt' . char . ''
      execute 'onoremap i' . char . ' :normal vi' . char . ''
      execute 'xnoremap a' . char . ' :normal! F' . char . 'vf' . char . ''
      execute 'onoremap a' . char . ' :normal va' . char . ''
    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.

提交回复
热议问题