Text objects are one of the power of Vim that I particulary like.
I wanted to create my personnal text object with the p (="previous") and n (="next") parameters. For instance if I type din) (="delete in next closing parenthesis") vim will look for the next parenthesis (even if it's in another line below) and delete it's content.
It is simple when I want to reach the previous/next parenthesis wich is in the same line as my cursor:
"Point the previous parenthesis onoremap ip) :<C-U>normal! F(vi(<CR>
"Point the next parenthesis onoremap in) :<C-U>normal! f(vi(<CR>
But the problems come when I want to modifie those mapping to extend the search outside of the line.
I finally found an alternative with this structure (
onoremap [keys] :[search] | [selection]<CR>):
"Point the previous parenthesis onoremap ip) :<C-U>call search('(','b')<Space><Bar><Space>normal! lvi)<CR>
"Point the next parenthesis onoremap in) :<C-U>call search('(')<Space><Bar><Space>normal! lvi)<CR>
But I have to use the "
search()" function because the "
/" command doesn't seem to work.
I also need to use "
<Space><Bar><Space>" to combine two commands (work as "
I see that using "
<C-U>" right after "
:" can avoid some border effect here
Is there a user-friendly way (a shorter and more readable answer) to do the same kind of mapping?
Personnally, text object is one of my favorite vim feature and I think it's a bit sad to struggle doing a mapping "on the fly" (but now I know that way, I can reproduce that without any problem).