epsilonhalbe
epsilonhalbe

Reputation: 15949

vim substitute within block selection on one line

I have the following expression in a latex file

\begin{dfn} \tag{Diagram $𝗗$ over a trisp $\Delta$}
          \label{dfn:Diagram D over a trisp Delta}

now i want to substitute all the spaces in the brackets on the second line with :. my idea was to visual select the expression by v% while being on one of the brackets and then :s/\ /:/g but this replaces all whitespaces and results in

::::::::::::::\label{dfn:Diagram:𝗗:over:a:trisp:Delta}

which results in the task of removing the : before the \label{…} as vim is a very powerful editor - there should be an easier way, that I don't know yet.

Upvotes: 1

Views: 862

Answers (1)

icyrock.com
icyrock.com

Reputation: 28608

Go to the first {, press v, press %. This will visually select the text between { and }. Then press : and enter s/\%V\ /:/g in your minibar. See this for explanation:

Note that otherwise g will replace all on the current line.

Upvotes: 6

Related Questions