nvim/lua/config/autocmd.lua

85 lines
2.2 KiB
Lua

-- vim.api.nvim_set_hl(0, 'NormalFloat', { bg = '#282828' })
-- vim.api.nvim_set_hl(0, 'FloatBorder', { bg = 'NONE' }) vim.api.nvim_set_hl(0, 'Pmenu', { bg = 'NONE' })
-- vim.api.nvim_set_hl(0, 'StatusLine', { bg = 'NONE' })
local function augroup(name)
return vim.api.nvim_create_augroup('neo_' .. name, { clear = true })
end
-- Use 'q' to quit from common plugins
vim.api.nvim_create_autocmd({ 'FileType' }, {
pattern = { 'qf', 'help', 'man', 'lspinfo', 'spectre_panel', 'lir' },
callback = function()
vim.cmd [[
nnoremap <silent> <buffer> q :close<CR>
set nobuflisted
]]
end,
})
-- use 2 spaces for cpp
vim.api.nvim_create_autocmd({ 'FileType' }, {
pattern = { 'cpp', 'cc', 'hpp', 'hh', 'md', 'markdown', 'java' },
callback = function()
vim.opt.ts = 4
vim.opt.sw = 4
vim.opt.expandtab = true
end,
})
-- Fixes Autocomment
vim.api.nvim_create_autocmd({ 'BufWinEnter' }, {
callback = function()
vim.cmd 'set formatoptions-=cro'
end,
})
-- Highlight Yanked Text
vim.api.nvim_create_autocmd({ 'TextYankPost' }, {
callback = function()
vim.highlight.on_yank { higroup = 'Visual', timeout = 200 }
end,
})
-- vim.api.nvim_create_augroup('diagnostics', { clear = true })
--
-- vim.api.nvim_create_autocmd({ 'DiagnosticChanged' }, {
-- group = 'diagnostics',
-- callback = function()
-- vim.diagnostic.setloclist { open = false }
-- end,
-- })
-- resize splits if window got resized
vim.api.nvim_create_autocmd({ 'VimResized' }, {
group = augroup 'resize_splits',
callback = function()
vim.cmd 'tabdo wincmd ='
end,
})
-- wrap and check for spell in text filetypes
vim.api.nvim_create_autocmd('FileType', {
group = augroup 'wrap_spell',
pattern = { 'gitcommit', 'markdown' },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
vim.opt_local.textwidth = 80
end,
})
vim.cmd [[
augroup change_cursor
au!
au ExitPre * :set guicursor=a:hor90
augroup 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()')