Skip to content

Instantly share code, notes, and snippets.

@takeshy
Last active September 3, 2016 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takeshy/c633a847295c231261601f659c0b7a86 to your computer and use it in GitHub Desktop.
Save takeshy/c633a847295c231261601f659c0b7a86 to your computer and use it in GitHub Desktop.
javascriptでimport先のファイルやejsファイルをsplitで開く
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