如何将 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/