reox
reox

Reputation: 5217

Jump to next occurence of different characters

I had some latex tables, that needed some header formating:

\begin{tabular}{|l|l|l|}
\hline
Foo bar bla & blabar & sdf \\
\hline
[table content]
\end{tablular}

where all items in the first row should get a \textbf{} tag.

\begin{tabular}{|l|l|l|}
\hline
\textbf{Foo bar bla} & \textbf{blabar} & \textbf{sdf} \\
\hline
[table content]
\end{tablular}

my macro goes like this:

^
qq
i
\textbf{<ESC>
f&
h
i
}<ESC>
ww
q
2@q

on the last item i dont get the closing bracket, because there is no more &. how can i jump with vim to to next occurence of & or \\?

Upvotes: 1

Views: 430

Answers (2)

Kent
Kent

Reputation: 195039

you could use :s instead of macro:

s/\(.*\)\\\\/\='\\textbf{' . substitute(submatch(1),'&','} & \\textbf{','g') . "}\\\\"/

Upvotes: 1

romainl
romainl

Reputation: 196496

Instead of:

f&

you could do a search:

/\v [&\\]

which will land you on the space before & and \, ready to do:

i}

\v means "very magic" and allows us to save some \.

Upvotes: 2

Related Questions