Created
March 20, 2017 08:49
-
-
Save damianbaar/93d3b8caa0478c399cdd49795217f7c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <leader>ti: call GetImport('')<CR> | |
function! GetImport(word) | |
let result = json_decode(system('importjs word '.expand('<cword>').' '.expand('%'))) | |
let content = result.fileContent | |
let cursorPos = getpos(".") | |
let originalLineCount = line("$") | |
let @a = content | |
normal! gg | |
execute "put a" | |
" Remove lingering line at the top: | |
" Restore cursor position, attempting to compensate for the resulting | |
" imports moving the original line up or down | |
let newLineCount = line("$") | |
let cursorPos[1] = cursorPos[1] + newLineCount - originalLineCount | |
call setpos(".", cursorPos) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment