Created
October 13, 2012 02:03
-
-
Save marczych/3882918 to your computer and use it in GitHub Desktop.
Vim: Take the word under the cursor, append the current buffer's extension, and open it using find.
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
nnoremap <silent> <C-o> :call FindFile()<CR> | |
function! FindFile() | |
" Get the word under cursor. | |
let cursorWord = expand("<cword>") | |
" Get the current file name and keep only the extension. | |
let currentFile = expand("%") | |
let extPos = stridx(currentFile, ".") | |
" Append an extension only if the current file has an extension. | |
if extPos != -1 | |
let extension = strpart(currentFile, extPos) | |
else | |
let extension = "" | |
endif | |
" Construct the file name. | |
let fileName = cursorWord.extension | |
" Open the file in the current buffer. | |
execute "find ".fileName | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment