开发者

Vim pattern to replace all instances of vspace

In technical papers typeset with latex we typically use a lot of "vspace" tricks to get the paper to lay out properly within the page limit. Of course, when the font or number of columns changes, they all break. What is a good way to replace all instances of ite开发者_如何学Cms like this:

\vspace{3.4mm}
\vspace{2in}
\vspace{-1.2in}
\vspace{-3mm}

with

\vspace{0mm}

using a vim pattern?


%s/vspace{[^}]\+}/vspace{0mm}/g

key:

  • %: search for pattern on all lines in file.
  • vspace{[^}]\+}: search for "vspace{1 or more of any character except '}'}"


One solution that does not depend on vim is to define the following

\newcommand{\myvspace}[1]{\vspace{#1}}

then when you want to change it to 0mm you just replace this by

\newcommand{\myvspace}[1]{\vspace{0mm}}


This seems to work for me:

:%s/\\vspace{.*}/\\vspace{0mm}/


A few of the other answers here will be too greedy in the case there is another } on the same line after the target }. The following should fix that:

:%s/vspace{\zs[^}]\+\ze}/0mm/g


:%s#\\vspace{\zs.*\ze}#0mm#g

Does this command do the job?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜