Created
March 31, 2020 15:44
-
-
Save tamago324/e7178f6c2898826fbb8d35617742b82e 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
scriptencoding utf-8 | |
" input() のときに getcmdline() で取得できる技 | |
function! NewTmpFile() abort | |
let l:winid = popup_create('', { | |
\ 'padding': [1, 1, 1, 1], | |
\ 'minwidth': 20, | |
\ 'line': 'cursor-1', | |
\ 'col': 'cursor+3', | |
\}) | |
redraw | |
let l:timer = timer_start(30, funcref('s:timer_callback', [l:winid]), { 'repeat': -1 }) | |
let l:ft = call('input', ['>>> ', '', 'filetype']) | |
let s:tmp = tempname() | |
" もし、空ならそのバッファに表示 | |
if line('$') == 1 && getline(1) ==# '' | |
exec 'e '.s:tmp | |
else | |
exec 'new '.s:tmp | |
endif | |
exec 'set ft='.l:ft | |
call timer_stop(l:timer) | |
call popup_close(l:winid) | |
endfunction | |
function! s:timer_callback(winid, ...) abort | |
let l:query = getcmdline() | |
call win_execute(a:winid, printf("call setline(1, 'FileType: %s')", l:query)) | |
" redraw は必要! | |
redraw | |
endfunction | |
call NewTmpFile() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment