Search a String within a Text Object
vim-operator-search is a really life-changing Vim plugin for me. It allows you to search a string within a text object, which is useful, for instance, when you want to search a certain string only in a function.
Imagine there is such a code below, which can't be shown in a screen without scrolling, and you want to search $arg
to investigate how it is used in the function:
$arg ... // <- not searched function longLongFunction($arg) { $arg ... // <- searched // ... snip ... $arg ... // <- searched // ... snip ... $arg ... // <- searched } $arg ... // <- not searched
You can search $arg
with simple keybind using vim-operator-search and vim-textobj-function with its extension, vim-textobj-function-php.
After installing the plugins described above, add the setting into your .vimrc
:
nmap <Space>/ <Plug>(operator-search)if
If your cursor is within the function, you can search $arg
by pushing <Space>/
. Of course, with another textobj-function plugins such as textobj-function-perl, textobj-function-ruby or others, you can utilise the functionality also in other languages.
See also: http://qiita.com/kentaro/items/dd981f7d1337d2fd8e94