-- close some filetypes with vim.api.nvim_create_autocmd({ 'FileType' }, { pattern = { 'qf', 'help', 'man', 'lspinfo', 'spectre_panel', 'lir' }, callback = function(event) vim.bo[event.buf].buflisted = false vim.keymap.set("n", "q", "close", { buffer = event.buf, silent = true }) end, }) vim.api.nvim_create_autocmd({ 'FileType' }, { pattern = { 'cpp', 'cc', 'hpp', 'hh', 'md', 'markdown', 'java' }, callback = function() vim.opt.ts = 2 vim.opt.sw = 2 vim.opt.expandtab = true end, }) -- Highlight on yank vim.api.nvim_create_autocmd({ 'TextYankPost' }, { callback = function() vim.highlight.on_yank { higroup = 'Visual', timeout = 200 } end, }) -- resize splits if window got resized vim.api.nvim_create_autocmd({ "VimResized" }, { callback = function() local current_tab = vim.fn.tabpagenr() vim.cmd("tabdo wincmd =") vim.cmd("tabnext " .. current_tab) end, }) vim.api.nvim_create_autocmd('FileType', { pattern = { 'gitcommit', 'markdown' }, callback = function() vim.opt_local.wrap = true vim.opt_local.spell = true vim.opt_local.textwidth = 80 end, }) function _G.set_terminal_keymaps() local opts = { buffer = 0 } vim.keymap.set('t', '', [[]], opts) vim.keymap.set('t', '', [[]], opts) end -- if you only want these mappings for toggle term use term://*toggleterm#* instead vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()') -- 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, }) vim.cmd [[ augroup change_cursor au! au ExitPre * :set guicursor=a:hor90 augroup END ]]