autocmd.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. -- leave insert when terminal process exits
  10. -- this prevents the window from closing
  11. vim.api.nvim_create_autocmd('TermClose', {
  12. command = 'stopinsert',
  13. })
  14. -- automatically enter/leave terminal mode
  15. vim.api.nvim_create_autocmd('TermOpen', { command = 'startinsert' })
  16. vim.api.nvim_create_autocmd({'WinEnter','BufWinEnter'}, {
  17. pattern = 'term://*',
  18. command = 'startinsert',
  19. })
  20. vim.api.nvim_create_autocmd('BufLeave', {
  21. pattern = 'term://*',
  22. command = 'stopinsert',
  23. })
  24. -- strip trailing whitespace
  25. vim.api.nvim_create_autocmd('BufWritePre', { command = '%s/\\s\\+$//e' })
  26. -- filetype specific options
  27. vim.api.nvim_create_autocmd('FileType', {
  28. pattern = 'markdown',
  29. callback = function()
  30. vim.bo.textwidth = 80
  31. end,
  32. })
  33. vim.api.nvim_create_autocmd('FileType', {
  34. pattern = 'typescript',
  35. callback = function()
  36. -- disable default indentation as it's pretty broken for jsdoc
  37. vim.opt_local.indentexpr = nil
  38. vim.opt_local.formatexpr = nil
  39. end,
  40. })