diff --git a/README.md b/README.md index c8b1d21..8d81d30 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,53 @@ # vim-flutter Vim commands for Flutter, including hot-reload-on-save and more. + +## Installation +`vim-flutter` is a Vimscript-only plugin, and makes heavy +use of Vim8's async jobs. It can be installed with a +package manager like `vim-plug`, for example. + +```vim +Plug 'thosakwe/vim-flutter' + +" Run :PlugInstall to install the plugin. +``` + +Ultimately, installation is up to you. + +## Options +* `g:flutter_command` - The Flutter executable path/name; defaults to `'flutter'`. +* `g:flutter_hot_reload_on_save` - Whether to auto hot-reload when `dart` files +are saved; defaults to `1`. + +## Provided Commands +* `:FlutterRun ` - calls `flutter run ` +* `:FlutterHotReload` - triggers a hot reload on the current Flutter process +* `:FlutterHotRestart` - triggers a hot restart on the current Flutter process +* `:FlutterQuit` - quits the current Flutter process +* `:FlutterDevices` - opens a new buffer, and writes the output of `flutter devices` to it +* `:FlutterSplit` - opens Flutter output in a horizontal split + +The following are self-explanatory: +* `:FlutterVSplit` +* `:FlutterTab` + +## Hot Reload on Save +A convenient feature to have when working with Flutter is +to automatically hot-reload an app once a file is saved. +By default, whenever a `dart` file is saved, *if and only if* +a Flutter process is running, it will be hot-reloaded. + +You can disable this by setting `g:hot_reload_on_save=0`, +*before* `vim-flutter` is loaded. + +## Example `.vimrc` +```vim +Plug 'thosakwe/vim-flutter' + +" Some of these key choices were arbitrary; +" it's just an example. +nnoremap fa :FlutterRun +nnoremap fq :FlutterQuit +nnoremap fr :FlutterHotReload +nnoremap fR :FlutterHotRestart +``` \ No newline at end of file diff --git a/autoload/flutter.vim b/autoload/flutter.vim index f0f02df..cb2b1a1 100644 --- a/autoload/flutter.vim +++ b/autoload/flutter.vim @@ -24,6 +24,12 @@ function! flutter#hot_reload() abort return flutter#send('r') endfunction +function! flutter#hot_reload_quiet() abort + if exists('g:flutter_job') + return flutter#send('r') + endif +endfunction + function! flutter#hot_restart() abort return flutter#send('R') endfunction diff --git a/plugin/flutter.vim b/plugin/flutter.vim index 5116207..d1222fc 100644 --- a/plugin/flutter.vim +++ b/plugin/flutter.vim @@ -19,7 +19,7 @@ command FlutterHotRestart call flutter#hot_restart() command FlutterQuit call flutter#quit() if g:flutter_hot_reload_on_save - autocmd FileType dart autocmd BufWritePre call flutter#hot_reload() + autocmd FileType dart autocmd BufWritePre call flutter#hot_reload_quiet() endif command FlutterSplit :split __Flutter_Output__