From db929434fa2f29e5674a5f24d71901b4fa458363 Mon Sep 17 00:00:00 2001 From: talha Date: Thu, 14 Dec 2023 11:49:47 +0500 Subject: Fix autoreload, added autocmd: - Added autoreload to fix reloading when file changed externally - Added autocmd to format python files on save --- lua/talha/autocmds.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lua/talha/autocmds.lua (limited to 'lua/talha/autocmds.lua') diff --git a/lua/talha/autocmds.lua b/lua/talha/autocmds.lua new file mode 100644 index 0000000..a892fa2 --- /dev/null +++ b/lua/talha/autocmds.lua @@ -0,0 +1,19 @@ +local autocmd_group = vim.api.nvim_create_augroup("Custom auto-commands", { clear = true }) + +vim.api.nvim_create_autocmd({ "BufWritePost" }, { + pattern = { "*.py" }, + desc = "Auto-format python files after saving", + callback = function() + local filename = vim.api.nvim_buf_get_name(0) + vim.cmd(":silent !autopep8 -i " .. filename) + vim.cmd(":silent !isort " .. filename) + end, + group = autocmd_group, +}) + +vim.api.nvim_create_autocmd({ "CursorHold" }, { + desc = "reload the file on changes", + command = "checktime", + group = autocmd_group, +}) + -- cgit v1.2.3