Skip to content

Instantly share code, notes, and snippets.

@sasq64
Created September 1, 2016 13:57
Show Gist options
  • Save sasq64/bb4e3c895c21859db533e628750e0291 to your computer and use it in GitHub Desktop.
Save sasq64/bb4e3c895c21859db533e628750e0291 to your computer and use it in GitHub Desktop.
Find functions and classes using silver searcher from vim
function! FindFunction(name)
cexpr! system('ag --vimgrep -G ".(cs\|c\|cpp\|h\|java)$" "[A-Za-z\*]+\s+([A-Za-z_]+::)?' . a:name . '\s*\([^\)]*\)\s*(?=\{)"')
endfunction
function! FindClass(name)
cexpr! system('ag --vimgrep -G ".(cs\|c\|cpp\|h\|java)$" "(class\|struct\|interface)\s+([A-Za-z_]+\s+)*' . a:name . '\s+(?!;)"')
endfunction
nmap <leader>af "zyiw:call FindFunction(@z)<cr>
nmap <leader>ac "zyiw:call FindClass(@z)<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment