summaryrefslogtreecommitdiffstats
path: root/init.lua
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-05-22 11:46:08 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-05-22 11:46:08 +0200
commit550ba704b6d0fabd3ac0077c2c1067029c8a0264 (patch)
treedd3ae750d505d6d8b10660441f70ab3a4205fa19 /init.lua
parente4c6e0bdc40df9f5420eed3f57553f6652cc033f (diff)
downloadnvim-config-550ba704b6d0fabd3ac0077c2c1067029c8a0264.tar.gz
nvim-config-550ba704b6d0fabd3ac0077c2c1067029c8a0264.zip
misc(nvim): reload buffer when its file changed on disk
Bump 'updatetime' to 1 second because it affects three things: - swap file save frequency - GitGutter signs update frequency - CursorHold and CursorHoldI trigger frequency 100ms is too high of a frequency. Enable focus events in tmux for nvim 'FocusGained' event, Add two event handlers, one for updating the buffer with `checktime`, another for logging a message when doing so.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index 3f7515c..7ffe81f 100644
--- a/init.lua
+++ b/init.lua
@@ -66,6 +66,24 @@ vim.api.nvim_create_autocmd({ "WinEnter", "TermOpen" }, {
end,
})
+vim.opt.updatetime = 1000 -- Swap file save frequency; also how often GitGutter signs update in ms
+-- Reload buffer when file has been modified outside of nvim
+vim.api.nvim_create_autocmd({ "FocusGained", "BufEnter", "CursorHold", "CursorHoldI" }, {
+ desc = "Reload buffer when modified outside of nvim",
+ group = vim.g.dotfiles.augroup,
+ pattern = "*",
+ command = "checktime",
+})
+-- Log a message when buffer is reloaded because the file has changed on disk outside of nvim
+vim.api.nvim_create_autocmd({ "FileChangedShellPost" }, {
+ desc = "Notify buffer reloaded because its file has changed on disk",
+ group = vim.g.dotfiles.augroup,
+ pattern = "*",
+ callback = function()
+ vim.notify("File changed on disk, buffer reloaded", vim.log.levels.WARN)
+ end,
+})
+
------------------------------------------------------------------------------------------------------------------------
-- Plugins
------------------------------------------------------------------------------------------------------------------------