Created
March 24, 2021 06:07
-
-
Save fvumbaca/1fe847f4bd4922afbbc4583a79e1de70 to your computer and use it in GitHub Desktop.
NeoVim Flutter Hot Reloading
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
" Flutter wrapper for hot-reloading | |
" Put this in your plugin directory (Default is $HOME/.config/nvim/plugin) | |
" Start your Flutter app with :FlutterRun | |
" all saves to flutter dart files will hot reload | |
command! FlutterRun :call FlutterStartServer() | |
command! FlutterStopRun :call FlutterStopRun() | |
command! FlutterHotReload :call FlutterHotReload() | |
function! FlutterHotReload() | |
if (s:flutter_run_job != 0) | |
call system('kill -USR1 $(cat /tmp/flutter.pid)') | |
else | |
echom 'Flutter is not running' | |
endif | |
endfunction | |
function! s:OnFlutterRunEvent(job_id, data, event) dict | |
if a:event == 'stdout' | |
echom 'Flutter: '.join(a:data) | |
elseif a:event == 'stderr' | |
echom 'Flutter error: '.join(a:data) | |
else | |
echom 'Flutter exited' | |
endif | |
endfunction | |
let s:flutter_run_job = 0 | |
function! FlutterStartServer() | |
if (s:flutter_run_job != 0) | |
echom "Flutter already running" | |
else | |
echom "Starting Flutter" | |
let s:callbacks = { | |
\ 'on_stdout': function('s:OnFlutterRunEvent'), | |
\ 'on_stderr': function('s:OnFlutterRunEvent'), | |
\ 'on_exit': function('s:OnFlutterRunEvent') | |
\ } | |
let s:flutter_run_job = jobstart(['bash', '-c', 'flutter run --pid-file /tmp/flutter.pid'], s:callbacks) | |
endif | |
endfunction | |
function! FlutterStopRun() | |
call jobstop(s:flutter_run_job) | |
let s:flutter_run_job = 0 | |
endfunction | |
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
" Copy the line below into your init.vim file | |
autocmd BufWritePost */lib/*.dart :call FlutterHotReload() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thats very neat!
i find this to be even faster than vim-flutter!