diff options
Diffstat (limited to 'lua/config/autocommands.lua')
| -rw-r--r-- | lua/config/autocommands.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lua/config/autocommands.lua b/lua/config/autocommands.lua new file mode 100644 index 0000000..8fe38c6 --- /dev/null +++ b/lua/config/autocommands.lua @@ -0,0 +1,33 @@ +local augroup = vim.api.nvim_create_augroup("UserConfig", {}) + +-- highlight yanked text +vim.api.nvim_create_autocmd("TextYankPost", { + group = augroup, + callback = function() + vim.highlight.on_yank() + end, +}) + +-- open file on previous position before quitting +vim.api.nvim_create_autocmd("BufReadPost", { + group = augroup, + callback = function() + local mark = vim.api.nvim_buf_get_mark(0, '"') + local lcount = vim.api.nvim_buf_line_count(0) + if mark[1] > 0 and mark[1] <= lcount then + pcall(vim.api.nvim_win_set_cursor, 0, mark) + end + end, +}) + +-- create directories if they don't exist +vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + callback = function() + local dir = vim.fn.expand('<afile>:p:h') + if vim.fn.isdirectory(dir) == 0 then + vim.fn.mkdir(dir, 'p') + end + end, +}) + |
