-- apply default terminal settings vim.api.nvim_create_autocmd('TermOpen', { callback = function() vim.bo.scrollback = 10000 vim.opt_local.number = false vim.opt_local.relativenumber = false vim.b.miniindentscope_disable = true end }) -- preserve window structure when exiting terminal via C-d vim.api.nvim_create_autocmd('TermClose', { callback = function(opts) -- don't trigger when force deleting if vim.api.nvim_buf_get_option(opts.buf, 'modified') then return end MiniBufremove.delete(opts.buf) end, -- needed so statusline properly updates nested = true, }) -- automatically enter/leave terminal mode vim.api.nvim_create_autocmd('TermOpen', { command = 'startinsert' }) vim.api.nvim_create_autocmd({'WinEnter','BufWinEnter'}, { pattern = 'term://*', command = 'startinsert', }) vim.api.nvim_create_autocmd('BufLeave', { pattern = 'term://*', command = 'stopinsert', }) -- rename vim.api.nvim_create_autocmd('User', { pattern = 'MiniFilesActionRename', callback = function(opts) local params = { files = {{ oldUri = vim.uri_from_fname(opts.data.from), newUri = vim.uri_from_fname(opts.data.to), }} } local bufnr = vim.fn.bufadd(opts.data.to) local clients = vim.lsp.get_clients({ bufnr = bufnr }) for _, client in ipairs(clients) do if client:supports_method('workspace/willRenameFiles') then local resp = client:request_sync('workspace/willRenameFiles', params, 5000, bufnr) if resp and resp.result ~= nil then vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding) end end end for _, client in ipairs(clients) do if client:supports_method('workspace/didRenameFiles') then client:notify('workspace/didRenameFiles', params) end end end, nested = true, }) -- formatting vim.api.nvim_create_autocmd('BufWritePre', { callback = function(opts) if vim.bo.filetype == 'diff' then return end if not vim.g.no_lsp_format then -- check if can LSP format local clients = vim.lsp.get_clients({ bufnr = opts.buf, method = 'textDocument/formatting' }) if #clients > 0 then vim.lsp.buf.format({ bufnr = opts.buf }) end end -- otherwise strip trailing whitespace vim.cmd('%s/\\s\\+$//e') end, }) -- filetype specific options vim.api.nvim_create_autocmd('FileType', { pattern = 'markdown', callback = function() vim.bo.textwidth = 80 end, })