Last active
September 3, 2016 04:52
-
-
Save takeshy/c633a847295c231261601f659c0b7a86 to your computer and use it in GitHub Desktop.
javascriptでimport先のファイルやejsファイルをsplitで開く
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! ReadJSFile() abort | |
let s:currentPos = col('.') | |
let s:colNum = s:currentPos - 1 | |
let s:lastPos = len(getline('.')) | |
let s:fileName = '' | |
while s:colNum > -1 | |
if getline('.')[s:colNum] =~ "\['\"\]" | |
break | |
end | |
let s:fileName = getline('.')[s:colNum] . s:fileName | |
let s:colNum = s:colNum - 1 | |
endwhile | |
while s:currentPos < s:lastPos | |
if getline('.')[s:currentPos] =~ "\['\"\]" | |
break | |
end | |
let s:fileName = s:fileName . getline('.')[s:currentPos] | |
let s:currentPos = s:currentPos + 1 | |
endwhile | |
let s:fullName = simplify(expand("%:h") . '/' . s:fileName) | |
if !filereadable(s:fullName) | |
if isdirectory(s:fullName) | |
let s:fullName = s:fullName . '/index.js' | |
else | |
let s:fullName = s:fullName . '.js' | |
endif | |
endif | |
execute ':sp ' . s:fullName | |
endfunction | |
autocmd FileType javascript nmap <C-g> :call ReadJSFile()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment