2024-05-22 13:59:00 +02:00
|
|
|
local function augroup(name)
|
|
|
|
return vim.api.nvim_create_augroup("my_" .. name, { clear = false })
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{ "BufEnter", "FocusGained", "InsertLeave", "WinEnter", "CmdlineLeave" },
|
|
|
|
{
|
|
|
|
group = augroup("toggle_relative_number"),
|
|
|
|
callback = function()
|
|
|
|
if not vim.opt.number:get() and not vim.opt.relativenumber:get() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
vim.opt.relativenumber = vim.api.nvim_get_mode().mode ~= "i"
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd(
|
|
|
|
{ "BufLeave", "FocusLost", "InsertEnter", "WinLeave", "CmdlineEnter" },
|
|
|
|
{
|
|
|
|
group = augroup("toggle_relative_number"),
|
|
|
|
callback = function(ev)
|
|
|
|
vim.opt.relativenumber = false
|
|
|
|
if ev.event == "CmdlineEnter" then
|
|
|
|
vim.cmd("redraw")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-12-04 09:24:43 +01:00
|
|
|
-- close some filetypes with <q>
|
2022-12-31 17:43:31 +01:00
|
|
|
vim.api.nvim_create_autocmd({ 'FileType' }, {
|
|
|
|
pattern = { 'qf', 'help', 'man', 'lspinfo', 'spectre_panel', 'lir' },
|
2023-12-04 09:24:43 +01:00
|
|
|
callback = function(event)
|
|
|
|
vim.bo[event.buf].buflisted = false
|
|
|
|
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true })
|
2022-12-31 17:43:31 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd({ 'FileType' }, {
|
2023-02-06 09:58:30 +01:00
|
|
|
pattern = { 'cpp', 'cc', 'hpp', 'hh', 'md', 'markdown', 'java' },
|
2022-12-31 17:43:31 +01:00
|
|
|
callback = function()
|
2024-01-19 11:30:25 +01:00
|
|
|
vim.opt.ts = 4
|
|
|
|
vim.opt.sw = 4
|
2022-12-31 17:43:31 +01:00
|
|
|
vim.opt.expandtab = true
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2023-12-04 09:24:43 +01:00
|
|
|
-- Highlight on yank
|
2022-12-31 17:43:31 +01:00
|
|
|
vim.api.nvim_create_autocmd({ 'TextYankPost' }, {
|
|
|
|
callback = function()
|
|
|
|
vim.highlight.on_yank { higroup = 'Visual', timeout = 200 }
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2023-04-08 23:47:10 +02:00
|
|
|
-- resize splits if window got resized
|
2023-12-04 09:24:43 +01:00
|
|
|
vim.api.nvim_create_autocmd({ "VimResized" }, {
|
2023-04-08 23:47:10 +02:00
|
|
|
callback = function()
|
2023-12-04 09:24:43 +01:00
|
|
|
local current_tab = vim.fn.tabpagenr()
|
|
|
|
vim.cmd("tabdo wincmd =")
|
|
|
|
vim.cmd("tabnext " .. current_tab)
|
2023-04-08 23:47:10 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd('FileType', {
|
|
|
|
pattern = { 'gitcommit', 'markdown' },
|
|
|
|
callback = function()
|
|
|
|
vim.opt_local.wrap = true
|
|
|
|
vim.opt_local.spell = true
|
2023-06-19 11:33:42 +02:00
|
|
|
vim.opt_local.textwidth = 80
|
2023-04-08 23:47:10 +02:00
|
|
|
end,
|
|
|
|
})
|
2023-07-02 22:17:37 +02:00
|
|
|
|
2023-12-04 09:24:43 +01:00
|
|
|
-- go to last loc when opening a buffer
|
|
|
|
vim.api.nvim_create_autocmd("BufReadPost", {
|
|
|
|
callback = function(event)
|
|
|
|
local exclude = { "gitcommit" }
|
|
|
|
local buf = event.buf
|
|
|
|
if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].lazyvim_last_loc then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
vim.b[buf].lazyvim_last_loc = true
|
|
|
|
local mark = vim.api.nvim_buf_get_mark(buf, '"')
|
|
|
|
local lcount = vim.api.nvim_buf_line_count(buf)
|
|
|
|
if mark[1] > 0 and mark[1] <= lcount then
|
|
|
|
pcall(vim.api.nvim_win_set_cursor, 0, mark)
|
|
|
|
end
|
2023-08-10 13:32:47 +02:00
|
|
|
end,
|
|
|
|
})
|
2023-12-04 09:24:43 +01:00
|
|
|
|
|
|
|
vim.cmd [[
|
|
|
|
augroup change_cursor
|
|
|
|
au!
|
|
|
|
au ExitPre * :set guicursor=a:hor90
|
|
|
|
augroup END
|
|
|
|
]]
|
2024-01-19 11:30:25 +01:00
|
|
|
|
|
|
|
-- Fixes Autocomment
|
2024-05-22 13:59:00 +02:00
|
|
|
-- vim.api.nvim_create_autocmd({ 'BufWinEnter' }, {
|
|
|
|
-- callback = function()
|
|
|
|
-- vim.cmd 'set formatoptions-=cro'
|
|
|
|
-- end,
|
|
|
|
-- })
|