feat: add some general usefull autocommands
This commit is contained in:
parent
8b5ffaa227
commit
236bb15139
1 changed files with 33 additions and 0 deletions
33
lua/config/autocommands.lua
Normal file
33
lua/config/autocommands.lua
Normal file
|
|
@ -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,
|
||||||
|
})
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue