문제

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