質問

I have numbers in the shape of (a/b) where a and b are integers. I would like to replace them with something like rat(a,b). Is that possible?

役に立ちましたか?

解決 2

Vim is good at Search and Replace:

:%s/(\(\d\+\)\/\(\d\+\))/rat(\1,\2)/g

Too much backslashs! Yet another command:

:%s@\v\((\d+)/(\d+)\)@rat(\1,\2)@g
  • We can use @ to separate patterns instead of /.
  • The very magic \v makes life easier.

I suggest you type :help :s to learn more.

他のヒント

I would do:

%s#\v(\d+)/(\d+)#rat(\1,\2)#g

The easier way to do this is probably to create a macro and replay it as many times as you need to.

  • press on qa then make the search & replace stuff
  • press q when done
  • then play the macro with @a

If you know regex, then you can go to Search patterns http://vim.wikia.com/wiki/Search_patterns

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top