-- don't auto comment new line vim.api.nvim_create_autocmd('BufEnter', { command = [[set formatoptions-=cro]] }) -- to make border as same as neovim ColorScheme vim.api.nvim_create_autocmd({ 'UIEnter', 'ColorScheme' }, { callback = function() local normal = vim.api.nvim_get_hl(0, { name = 'Normal' }) if not normal.bg then return end io.write(string.format('\027Ptmux;\027\027]11;#%06x\007\027\\', normal.bg)) io.write(string.format('\027]11;#%06x\027\\', normal.bg)) end, }) vim.api.nvim_create_autocmd('UILeave', { callback = function() io.write('\027Ptmux;\027\027]111;\007\027\\') io.write('\027]111\027\\') end, }) -- Highlight on yank vim.api.nvim_create_autocmd('TextYankPost', { callback = function() vim.highlight.on_yank() end, }) -- go to last loc when opening a buffer -- this mean that when you open a file, you will be at the last position vim.api.nvim_create_autocmd('BufReadPost', { 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, }) -- auto close brackets vim.api.nvim_create_autocmd('FileType', { pattern = 'man', command = [[nnoremap q :quit]] }) -- show cursor line only in active window local cursorGrp = vim.api.nvim_create_augroup('CursorLine', { clear = true }) vim.api.nvim_create_autocmd({ 'InsertLeave', 'WinEnter' }, { pattern = '*', command = 'set cursorline', group = cursorGrp, }) vim.api.nvim_create_autocmd( { 'InsertEnter', 'WinLeave' }, { pattern = '*', command = 'set nocursorline', group = cursorGrp } ) -- Enable spell checking for certain file types vim.api.nvim_create_autocmd( { 'BufRead', 'BufNewFile' }, -- { pattern = { "*.txt", "*.md", "*.tex" }, command = [[setlocal spell setlocal spelllang=en,de]] } { pattern = { '*.txt', '*.md', '*.tex' }, callback = function() vim.opt.spell = true vim.opt.spelllang = 'en,de' end, } ) -- close some filetypes with vim.api.nvim_create_autocmd('FileType', { group = vim.api.nvim_create_augroup('close_with_q', { clear = true }), pattern = { 'PlenaryTestPopup', 'help', 'lspinfo', 'man', 'notify', 'qf', 'spectre_panel', 'startuptime', 'tsplayground', 'neotest-output', 'checkhealth', 'neotest-summary', 'neotest-output-panel', }, callback = function(event) vim.bo[event.buf].buflisted = false vim.keymap.set('n', 'q', 'close', { buffer = event.buf, silent = true }) end, }) -- resize neovim split when terminal is resized vim.api.nvim_command('autocmd VimResized * wincmd =')