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 +++++++++++++++++++ lua/talha/init.lua | 1 + lua/talha/packer.lua | 2 ++ lua/talha/set.lua | 2 -- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 lua/talha/autocmds.lua (limited to 'lua/talha') 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, +}) + diff --git a/lua/talha/init.lua b/lua/talha/init.lua index 2babaca..5dabc12 100644 --- a/lua/talha/init.lua +++ b/lua/talha/init.lua @@ -1,4 +1,5 @@ require("talha.remap") require("talha.set") require("talha.functions") +require("talha.autocmds") diff --git a/lua/talha/packer.lua b/lua/talha/packer.lua index eea7520..7b97acf 100644 --- a/lua/talha/packer.lua +++ b/lua/talha/packer.lua @@ -15,6 +15,8 @@ return require('packer').startup(function(use) -- colorschemes use { "ellisonleao/gruvbox.nvim" } + use {"bluz71/vim-nightfly-colors"} + use {"dasupradyumna/midnight.nvim"} use { "theprimeagen/harpoon" } diff --git a/lua/talha/set.lua b/lua/talha/set.lua index 0366b03..814a837 100644 --- a/lua/talha/set.lua +++ b/lua/talha/set.lua @@ -24,9 +24,7 @@ op.cursorline = true op.scrolloff = 8 --- autoreload a file after inactivity op.autoread = true -vim.api.nvim_command([[au CursorHold * checktime]]) op.updatetime = 50 -- cgit v1.2.3