vim 使用当前行作为参考点进行搜索和替换 [英] vim search and replace using current line as reference point
本文介绍了vim 使用当前行作为参考点进行搜索和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用当前行作为参考来指定搜索和替换范围?我可以使用像
Is there a way to specify search and replace range using the current line as a reference? I can specify range using explicit line numbers like
:5,15s/foo/bar/g
仅在第 5 到 15 行进行搜索和替换.如何指定从当前行到当前行下方(或上方)10 行"之类的范围?
to do the search and replace on only lines 5 to 15. How to specify a range like "from the current line to 10 lines below (or above) the current line"?
推荐答案
您可以使用 .
表示当前位置,.+10
表示向下 10 行:
You can use .
for the current position, and .+10
for 10 lines down:
:.,.+10s/foo/bar/g
其他一些有用的范围:
%
表示整个文件.示例::%s/foo/bar/g
.'<,'>
用于视觉选择块的行.这可能会让您获得比您想要的更多的视觉选择在行的中间开始或结束.包括整行.'a,'b
从标记 a 到标记 b..,$
从当前行到文件末尾.
%
for the whole file. Example::%s/foo/bar/g
.'<,'>
for the lines of visually selected block. This might get you more than you want of the visual selection starts or ends in the middle of a line. The whole line is included.'a,'b
from mark a to mark b..,$
from the current line to the end of the file.
这篇关于vim 使用当前行作为参考点进行搜索和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文