Is there a Vim plugin, script, or function out there that allows Vim search to be extended in order to match camel-cased words when I type its capital letters in succession?
Here is an example to clarify. Let’s say I am looking for WordInQuestion
. I would like to be able to just type /wiq
in order to find it.
As an added bonus, it would be nice if I could find getWordInQuestion
by typing /gwiq
which means the first letter of the word I am looking for may be lower case.
The described functionality can be easily implemented by means of Vimscript. Let us consider the following custom mappings.
nnoremap <expr> <leader>/ SearchCamelCase('/')
nnoremap <expr> <leader>? SearchCamelCase('?')
function! SearchCamelCase(dir)
call inputsave()
let ab = input(a:dir)
call inputrestore()
let l = filter(split(toupper(ab), '\zs'), 'v:val =~ "\\w"')
if len(l) > 0
let l[0] = '[' . l[0] . tolower(l[0]) . ']'
end
let @/ = '\C\<' . join(map(l, 'v:val . "[0-9a-z_]*"'), '') . '\>'
return a:dir . "\r"
endfunction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With