nvim/lua/config/autocmd.lua

83 lines
2.2 KiB
Lua
Raw Normal View History

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' }, {
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,
})
function _G.set_terminal_keymaps()
local opts = { buffer = 0 }
vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
vim.keymap.set('t', '<C-w>', [[<C-\><C-n><C-w>]], opts)
end
-- if you only want these mappings for toggle term use term://*toggleterm#* instead
vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')
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
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
vim.api.nvim_create_autocmd({ 'BufWinEnter' }, {
callback = function()
vim.cmd 'set formatoptions-=cro'
end,
})