autocmd.lua 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. local autocmd = vim.api.nvim_create_autocmd
  2. local cmd = vim.cmd
  3. local function get_path(str, sep)
  4. sep = sep or '/'
  5. return str:match("(.*" .. sep .. ")")
  6. end
  7. local function file_exists(name)
  8. local f = io.open(name, "r")
  9. if f ~= nil then
  10. io.close(f)
  11. return true
  12. else
  13. return false
  14. end
  15. end
  16. autocmd(
  17. 'VimEnter',
  18. {
  19. pattern = '*',
  20. callback = function(ev)
  21. local opened = ev.file
  22. local folder_opened = string.find(opened, 'NERD_tree')
  23. if folder_opened then
  24. local folder = get_path(opened)
  25. local exist = file_exists(folder .. '.env.lua')
  26. if exist then
  27. cmd('source ' .. folder .. '.env.lua')
  28. end
  29. end
  30. end,
  31. }
  32. )
  33. autocmd(
  34. 'BufWritePre',
  35. {
  36. pattern = '*',
  37. command = ':%s/\\s\\+$//e'
  38. }
  39. )
  40. -- local function reload_plugins()
  41. -- cmd':Reload'
  42. -- cmd':Restart'
  43. -- cmd':PackerCompile'
  44. -- cmd':PackerSync'
  45. -- end
  46. -- autocmd(
  47. -- 'BufWritePost',
  48. -- {
  49. -- pattern = '*/plugins.lua',
  50. -- callback = reload_plugins,
  51. -- }
  52. -- )