Skip to content

Instantly share code, notes, and snippets.

@takeshy takeshy/readfile.vim
Last active Sep 3, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.