I have created a vmap text object for selecting the text of a single LaTeX item:
vmap im ?\item<CR>o/\item\|\end{itemize}<CR>b$
But this has the annoying feature that I lose my current search term. I have read that search terms are restored when the search happens inside a function call, so I wanted to convert the map to just call a function that would do the searches:
function! ItemizeTextObject()
?\item
normal o
/\item|\end{itemize}
normal b$
endfunction
vmap in :call ItemizeTextObject()<CR>
Unfortunately, this does not work: I get an error ("Pattern not found: item|end{itemize}"), no text at all is selected, and a new line is inserted below the line my cursor is on. I tried several variations of this, and had no success.
I think the basic problem is that I have to preserve the visual mode when calling the function (the o
in my command should switch to the other end of the selection, but it inserts a new line instead), but I don't know how.
Update:
I try to get the following behaviour: In a text like this:
egin{itemize}
item lorem ipsum...
item piece of text I want to select,
the *CURSOR* is here, and there is more text
that follows
item lorem ipsum...
end{itemize}
I want to hit vin
, and then the text block in the middle should be selected:
item piece of text I want to select,
the *CURSOR* is here, and there is more text
that follows
that means the text from the beginning of the previous item
, until but not including the next item
or end{itemize}
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…