Delete / Yank lines from current line up to and including line containing search pattern

latexvim

Suppose I have the following text (cursor is in middle of first word 'begin.'

blah blah blah blah stuff stuff stuff
\\\begin{tabular}
{
|p{0.25\textwidth}
|p{0.2\textwidth}
|p{0.5\textwidth}
|}
\hline
Item & Type & Notes\\\hline
Text text text text text text text text &
Text text text text text &
Text text text text text text text text text text text text text text text text text
  text text text text text text\\\hline

Installation instructions &
.txt / .html / TBD &
Installation help should be conspicuous but not the central item\\\hline
\end{tabular}
blah blah blah more stuff more stuff

I want to cut the table out and move it somewhere else. The lines are actually much longer so they wrap several times and I can't easily determine how many lines I want to cut.

I type
d
2
/
a
r
}
/
e

to delete until the second match of "ar}" stop at the 'e'nd of the pattern.

But this grabs from the middle of the word 'begin' to the end of where I want to cut. I'd like to grab complete lines and I feel like there should be a shortcut for this in under 6 keystrokes. I'm not using Latex-VIM because it doesn't like my standard Windows installation of GVIM so no, I can't (as far as I know) easily grab from the \begin to the \end. I'd love to be proven wrong on that.


Yes, this question is potentially a crossover of StackExchange sites including Tex, StackOverflow, and Unix. Feel free to suggest a better site for asking this.

Best Answer

With an Ex command:

:,/\\e/d

Breakdown:

  • Structure of an Ex command: :{range}command{address}.
  • One can use line numbers, marks or search patterns to delimit the range, here we start with the current line, usually a . but it can be skipped like here, and we finish with a pattern matching \end.
  • We delete the lines in that range.

With a combination of search and contextual marks:

/\\e<CR>
d''

Breakdown:

  • Search for \e.
  • delete from here to the line of the previous cursor position.

With visual mode:

v/\\e<CR>
V
d

Breakdown:

  • Visually select from here to \e.
  • Switch to visual line block.
  • delete the lines in the selection.

Variation of the method above with an Ex command instead of a normal mode command:

v/\\e<CR>
:'<,'>d

Breakdown:

  • Visually select from here to \e.
  • Enter command-line mode with :, the '<,'> range is inserted automatically.
  • delete the lines in the selection.
Related Question