autocmd.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. -- apply default terminal settings
  2. vim.api.nvim_create_autocmd('TermOpen', {
  3. callback = function()
  4. vim.bo.scrollback = 10000
  5. vim.opt_local.number = false
  6. vim.opt_local.relativenumber = false
  7. end
  8. })
  9. -- preserve window structure when exiting terminal via C-d
  10. vim.api.nvim_create_autocmd('TermClose', {
  11. callback = function(opts)
  12. -- don't trigger when force deleting
  13. if vim.api.nvim_buf_get_option(opts.buf, 'modified') then
  14. return
  15. end
  16. MiniBufremove.delete(opts.buf)
  17. end,
  18. -- needed so statusline properly updates
  19. nested = true,
  20. })
  21. -- automatically enter/leave terminal mode
  22. vim.api.nvim_create_autocmd('TermOpen', { command = 'startinsert' })
  23. vim.api.nvim_create_autocmd({'WinEnter','BufWinEnter'}, {
  24. pattern = 'term://*',
  25. command = 'startinsert',
  26. })
  27. vim.api.nvim_create_autocmd('BufLeave', {
  28. pattern = 'term://*',
  29. command = 'stopinsert',
  30. })
  31. -- strip trailing whitespace
  32. vim.api.nvim_create_autocmd('BufWritePre', {
  33. callback = function(opts)
  34. if vim.bo.filetype == 'diff' then
  35. return
  36. end
  37. vim.cmd('%s/\\s\\+$//e')
  38. end,
  39. })
  40. -- filetype specific options
  41. vim.api.nvim_create_autocmd('FileType', {
  42. pattern = 'markdown',
  43. callback = function()
  44. vim.bo.textwidth = 80
  45. end,
  46. })