1
0

autocmd.lua 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. vim.b.miniindentscope_disable = true
  8. end
  9. })
  10. -- preserve window structure when exiting terminal via C-d
  11. vim.api.nvim_create_autocmd('TermClose', {
  12. callback = function(opts)
  13. -- don't trigger when force deleting
  14. if vim.api.nvim_buf_get_option(opts.buf, 'modified') then
  15. return
  16. end
  17. MiniBufremove.delete(opts.buf)
  18. end,
  19. -- needed so statusline properly updates
  20. nested = true,
  21. })
  22. -- automatically enter/leave terminal mode
  23. vim.api.nvim_create_autocmd('TermOpen', { command = 'startinsert' })
  24. vim.api.nvim_create_autocmd({'WinEnter','BufWinEnter'}, {
  25. pattern = 'term://*',
  26. command = 'startinsert',
  27. })
  28. vim.api.nvim_create_autocmd('BufLeave', {
  29. pattern = 'term://*',
  30. command = 'stopinsert',
  31. })
  32. -- strip trailing whitespace
  33. vim.api.nvim_create_autocmd('BufWritePre', {
  34. callback = function(opts)
  35. if vim.bo.filetype == 'diff' then
  36. return
  37. end
  38. vim.cmd('%s/\\s\\+$//e')
  39. end,
  40. })
  41. -- filetype specific options
  42. vim.api.nvim_create_autocmd('FileType', {
  43. pattern = 'markdown',
  44. callback = function()
  45. vim.bo.textwidth = 80
  46. end,
  47. })
  48. vim.api.nvim_create_autocmd('FileType', {
  49. pattern = 'http',
  50. callback = function(opts)
  51. vim.keymap.set('n', '<Leader>r', '<Plug>RestNvim', {
  52. buffer = opts.buf,
  53. })
  54. end,
  55. })