diff options
| author | Crony Akatsuki <crony@cronyakatsuki.xyz> | 2025-10-21 10:30:10 +0200 |
|---|---|---|
| committer | Crony Akatsuki <crony@cronyakatsuki.xyz> | 2025-10-21 10:30:10 +0200 |
| commit | 236bb15139e161eca3cab8ebf6414e2d075063c9 (patch) | |
| tree | 241d5c45dd0d9ce8a13baba3b8638d702f9c3e6b /lua/config/autocommands.lua | |
| parent | 8b5ffaa227ec2f052444bcd1947e92d6a620724c (diff) | |
| download | nvim-236bb15139e161eca3cab8ebf6414e2d075063c9.zip nvim-236bb15139e161eca3cab8ebf6414e2d075063c9.tar.gz | |
feat: add some general usefull autocommands
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, +}) + |
