Files
dotfiles/.config/nvim/lua/autocmds.lua
2025-11-09 13:41:37 +01:00

22 lines
788 B
Lua

-- Autocommand: trigger Flutter hot reload on save
--
-- This runs whenever you save a *.dart file (BufWritePost).
-- It checks if a tmux session named "flutter" exists.
-- If it does, it sends the keys "r<Enter>" to the "app" window
-- of that session, which tells `flutter run` to hot-reload.
--
-- Workflow:
-- 1. Start tmux: tmux new -s flutter -n app
-- 2. Inside tmux "app" window, run: flutter run
-- 3. Open another window/pane for nvim.
-- 4. Whenever you :w a Dart file in nvim, hot reload will fire.
--
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = "*.dart",
callback = function()
local result = vim.fn.system({ "tmux", "send-keys", "-t", "flutter:app", "r", "Enter" })
vim.notify("Flutter hot reload triggered", vim.log.levels.INFO)
end,
})