Last active
July 20, 2017 22:04
-
-
Save Arc0re/d8f92253d5a7c201644e90dbd56a319d to your computer and use it in GitHub Desktop.
Quick and dirty "goto definition" that looks up for the last selected (in visual mode) string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! GotoDefinition() | |
let selectedStuff = s:get_visual_selection() | |
if strlen(selectedStuff)>0 | |
exe 'vimgrep /' . selectedStuff . '/ **/*' | |
exe 'copen' | |
elseif | |
echo 'Nothing selected. Aborting.' | |
endif | |
endfunction GotoDefinition | |
" https://stackoverflow.com/a/6271254 | |
function! s:get_visual_selection() | |
" Why is this not a built-in Vim script function?! | |
let [lnum1, col1] = getpos("'<")[1:2] | |
let [lnum2, col2] = getpos("'>")[1:2] | |
let lines = getline(lnum1, lnum2) | |
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)] | |
let lines[0] = lines[0][col1 - 1:] | |
return join(lines, "\n") | |
endfunction | |
command! GotoDef call GotoDefinition() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment