vim - 限制 Vim 中代码的搜索范围

标签 vim vi

如何将 Vim 中的搜索范围限制为光标当前所在的函数/类/代码块,而不必弄清楚行号是什么?能够在视觉选择中搜索也可以,因为有选择当前代码块的方法。

(类似于 this 问题,但更通用)

最佳答案

为简洁起见:

" tldr;
v i { <ESC> /\%Vsearch-term

" Search for search-term within the current code block (defined by curly braces {}).
" Begin in normal mode, then enter the following:

" enter visual mode
v

" look for stuff in-between the current...
i

" curly braces enclosure
{

" (now the enclosure should be highlighted)

" exit visual mode
<ESC>

" search the last visual mode selection for search-term
/\%Vsearch-term

" note: to search within other enclosures, you can substitute curly braces for: 
" - parenthesis, 
" - square brackets, 
" - or other enclosure pair characters

关于vim - 限制 Vim 中代码的搜索范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2921752/

相关文章:

vim - 如何剪切/抽取 Vim "inner"或 "block"对象的一半

vim - 如何在不创建新行的情况下选择SuperTab完成建议?

VIM 总是使用标签页

vim - 如何获取由数字指定的缓冲区的 'filetype'?

regex - Vim - 如何在所有缓冲区中运行非正常模式命令?

regex - 在 VI 中搜索和替换正则表达式,需要说明

perl - 有没有办法在 vim 中为 Perl 启用代码完成?

linux - Vim 正则表达式查找和替换

windows - Vim(7.3.3 Windows 64 位): Add ^M to end of line if there is none (ff=unix)

vim - vim 中代码块和宏的最佳策略是什么?