vimviyankvim-registers

Vim - capture in between slashes?


Is there a motion for capturing text in between / or \? I know there is motions for other symbols ---

ci" - Capture 'text' inside "text"

vi( - Visual capture int var inside foo(int var)

di[ - Delete word [word] into []

The only workaround I can find is by using Vim Surround, and using it to change surrounding \ into " (cs\"), and then working from there. However, not only is it that kind of tedious, but the plugin only supports backslashes, not forward.


Solution

  • You could write your own text-object for this pretty easily.

    onoremap <silent> i/ :<C-U>normal! T/vt/<CR> " inside /
    onoremap <silent> a/ :<C-U>normal! F/vf/<CR> " around /
    

    For it to work with visual mode :

    xnoremap <silent> i/ :<C-U>normal! T/vt/<CR> " inside /
    xnoremap <silent> a/ :<C-U>normal! F/vf/<CR> " around /
    

    Similarly you could also do for \

    Edit: Added info comments.