在 vim 中的特定行中搜索和替换 [英] Search and replace in vim in specific lines

查看:32
本文介绍了在 vim 中的特定行中搜索和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用

:5,12s/foo/bar/g

搜索 foo 并在第 5 行和第 12 行之间用 bar 替换它.我怎么能只在第 5 行和第 12 行(而不是在之间)?

to search for foo and replace it by bar between lines 5 and 12. How can I do that only in line 5 and 12 (and not in the lines in between)?

推荐答案

Vim 有特殊的正则表达式原子,可以匹配某些行、列等;您可以使用它们(可能除了范围之外)来限制匹配:

Vim has special regular expression atoms that match in certain lines, columns, etc.; you can use them (possibly in addition to the range) to limit the matches:

:5,12s/\(\%5l\|\%12l\)foo/bar/g

:help/\%l

这篇关于在 vim 中的特定行中搜索和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆