45 lines
1.4 KiB
Lua
45 lines
1.4 KiB
Lua
-- [[ Basic Autocommands ]]
|
|
-- See `:help lua-guide-autocommands`
|
|
|
|
-- Highlight when yanking (copying) text
|
|
-- Try it with `yap` in normal mode
|
|
-- See `:help vim.highlight.on_yank()`
|
|
vim.api.nvim_create_autocmd("TextYankPost", {
|
|
desc = "Highlight when yanking (copying) text",
|
|
group = vim.api.nvim_create_augroup("highlight-yank", { clear = true }),
|
|
callback = function() vim.hl.on_yank() end,
|
|
})
|
|
|
|
|
|
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
|
|
desc = "diagnostics on hold",
|
|
group = vim.api.nvim_create_augroup("diagnostics", { clear = true }),
|
|
callback = function() vim.diagnostic.open_float(nil, { focus = false }) end,
|
|
})
|
|
|
|
-- TODO: check if it interferes with C-s shortcut
|
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
|
desc = "create parent folders automatically",
|
|
group = vim.api.nvim_create_augroup("create-parent-automatically", { clear = true }),
|
|
callback = function()
|
|
vim.cmd ":silent !mkdir -p %:p:h"
|
|
end,
|
|
})
|
|
|
|
|
|
vim.api.nvim_create_autocmd("BufReadPost", {
|
|
pattern = { "*" },
|
|
desc = "When editing a file, always jump to the last known cursor position",
|
|
group = vim.api.nvim_create_augroup("last-location", { clear = true }),
|
|
callback = function()
|
|
local line = vim.fn.line "'\""
|
|
if
|
|
line >= 1
|
|
and line <= vim.fn.line "$"
|
|
and vim.bo.filetype ~= "commit"
|
|
and vim.fn.index({ "xxd", "gitrebase" }, vim.bo.filetype) == -1
|
|
then
|
|
vim.cmd 'normal! g`"'
|
|
end
|
|
end,
|
|
})
|