【发布时间】:2011-08-03 13:13:34
【问题描述】:
我想在 vim 中做一些代码重构。我发现以下 gem 可以将转换应用于所有缓冲区。
:dobuf %s/match/replace/gc
我的代码布局为根目录,其中包含依赖项目录和构建目录。我想从 ./src ./include 和 ./tests 加载所有 .cc 、 .h 和 .proto 文件。但不是从依赖项和构建目录到后台/隐藏缓冲区。我想这样做是为了使用上面的命令进行重构。
如果有人知道执行用例的更简洁的方法,请展示出来。
注意:I know you can string together find and sed to do this from the shell,但如果可能的话,我更喜欢在 vim 中执行此操作。我上面介绍的模式中的 /gc 前缀用于确认每次匹配的替换,我需要这个功能,因为我经常不想替换某些匹配,find 和 sedsolution 过于严格和挑剔在尝试我的用例时,在进行就地替换时也很容易破坏文件。
使用 sed 和 find 供参考:
列出候选替换:
find src include tests -name *.h -or -name *.cc -or -name *.proto|
xargs sed -n 's/ListServices/list_services/p'
执行替换:
`find src include tests -name *.h -or -name *.cc -or -name *.proto|
xargs sed -i 's/ListServices/list_services`'
【问题讨论】:
-
(OT) 抱歉打扰:你能重新打开stackoverflow.com/questions/7568983/…吗?我有一个我认为有价值的回复...如果您认为该回复没有增加 SO 的价值,您仍然可以删除该问题。
标签: c++ vim refactoring