1

I'm trying to convert a bunch of .textile files into their equivalent .markdown files.

I would like a vim search/replace command to replace all h1., h2., h3., etc. patterns with the associated number of # characters. So, h1. would become #, h2. would be come ## and so forth.

I think what I want to use is the \=repeat command, but I'm a bit lost as to what arguments to pass it.

Here is what I have so far. It replaces the correct matches, but it just deletes them and gives me errors:

:1,$s/h\d./\=repeat('#',submatch(0))

What are the proper arguments to pass to the \=repeat command?

4

1 回答 1

2

这条线可以帮助你:

%s/\vh(\d)\./\=repeat('#',submatch(1))

你用过submatch(0),它是整个匹配的字符串 : h and number and any char (here you had another problem, you should escape the period ),所以它不会做你所期望的。

于 2013-07-24T15:40:55.743 回答