You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.7 KiB

  1. local aucmd_dict = {
  2. VimEnter = {
  3. {
  4. callback = function()
  5. local function find_project_root()
  6. local current_dir = vim.fn.getcwd()
  7. while current_dir ~= "/" do
  8. if vim.fn.isdirectory(current_dir .. "/.git") == 1 or vim.fn.filereadable(current_dir .. "/.nvim.lua") then
  9. return current_dir
  10. end
  11. current_dir = vim.fn.fnamemodify(current_dir, ":h")
  12. end
  13. return vim.fn.getcwd()
  14. end
  15. local project_root = find_project_root()
  16. local project_specific_conf_file = project_root .. "/.nvim.lua"
  17. if vim.fn.filereadable(project_specific_conf_file) == 1 then
  18. vim.cmd("source " .. project_specific_conf_file)
  19. print("Sourced project specific config file: " .. project_specific_conf_file)
  20. end
  21. end
  22. }
  23. },
  24. FileType = {
  25. {
  26. -- Set tabstop to 2 for Dart, Vue, JavaScript, TypeScript, and JSON files
  27. pattern = "dart,vue,javascript,typescript,json,markdown",
  28. callback = function()
  29. vim.opt_local.tabstop = 2
  30. vim.opt_local.softtabstop = 2
  31. vim.opt_local.shiftwidth = 2
  32. end,
  33. },
  34. {
  35. pattern = 'dart',
  36. callback = function ()
  37. vim.bo.commentstring = '// %s'
  38. end
  39. },
  40. },
  41. BufWritePre = {
  42. {
  43. -- Remove trailing whitespace on save
  44. command = [[%s/\s\+$//e]],
  45. },
  46. },
  47. BufRead = {
  48. {
  49. -- Return cursor to where it was previously when re-opening a file
  50. callback = function()
  51. if vim.fn.expand('%:p') ~= '.git/COMMIT_EDITMSG' and vim.fn.line("'\"") > 1 and vim.fn.line("'\"") <= vim.fn.line("$") then
  52. vim.cmd("normal! g`\"")
  53. end
  54. end
  55. },
  56. {
  57. -- Set syntax for Dockerfiles
  58. pattern = { '*.docker' },
  59. callback = function()
  60. vim.opt_local.syntax = 'dockerfile'
  61. end
  62. },
  63. {
  64. pattern = { '*.blade.php' },
  65. command = [[set syntax=html]],
  66. },
  67. },
  68. BufNewFile = {
  69. {
  70. -- Set syntax for Dockerfiles
  71. pattern = { '*.docker' },
  72. callback = function()
  73. vim.opt_local.syntax = 'dockerfile'
  74. end
  75. },
  76. },
  77. }
  78. for event, opt_tbls in pairs(aucmd_dict) do
  79. for _, opt_tbl in pairs(opt_tbls) do
  80. vim.api.nvim_create_autocmd(event, opt_tbl)
  81. end
  82. end