treesitter.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. return {
  2. {
  3. "nvim-treesitter/nvim-treesitter",
  4. build = ":TSUpdate",
  5. config = function()
  6. local configs = require("nvim-treesitter.configs")
  7. configs.setup({
  8. ensure_installed = {
  9. "c",
  10. "lua",
  11. "vim",
  12. "vimdoc",
  13. "javascript",
  14. "html",
  15. "rust",
  16. "regex",
  17. "typescript",
  18. "tsx",
  19. "typst",
  20. "markdown"
  21. },
  22. sync_install = false,
  23. highlight = { enable = true },
  24. indent = { enable = true },
  25. })
  26. end,
  27. },
  28. {
  29. "nvim-treesitter/nvim-treesitter-textobjects",
  30. build = ":TSUpdate",
  31. config = function()
  32. require("nvim-treesitter.configs").setup({
  33. textobjects = {
  34. select = {
  35. enable = true,
  36. -- Automatically jump forward to textobj, similar to targets.vim
  37. lookahead = true,
  38. keymaps = {
  39. -- You can use the capture groups defined in textobjects.scm
  40. ["af"] = "@function.outer",
  41. ["if"] = "@function.inner",
  42. ["ac"] = "@class.outer",
  43. -- You can optionally set descriptions to the mappings (used in the desc parameter of
  44. -- nvim_buf_set_keymap) which plugins like which-key display
  45. ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
  46. -- You can also use captures from other query groups like `locals.scm`
  47. ["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" },
  48. ["ap"] = "@parameter.outer",
  49. ["ip"] = "@parameter.inner",
  50. },
  51. -- You can choose the select mode (default is charwise 'v')
  52. --
  53. -- Can also be a function which gets passed a table with the keys
  54. -- * query_string: eg '@function.inner'
  55. -- * method: eg 'v' or 'o'
  56. -- and should return the mode ('v', 'V', or '<c-v>') or a table
  57. -- mapping query_strings to modes.
  58. selection_modes = {
  59. ["@parameter.outer"] = "v", -- charwise
  60. ["@function.outer"] = "V", -- linewise
  61. ["@class.outer"] = "<c-v>", -- blockwise
  62. },
  63. -- If you set this to `true` (default is `false`) then any textobject is
  64. -- extended to include preceding or succeeding whitespace. Succeeding
  65. -- whitespace has priority in order to act similarly to eg the built-in
  66. -- `ap`.
  67. --
  68. -- Can also be a function which gets passed a table with the keys
  69. -- * query_string: eg '@function.inner'
  70. -- * selection_mode: eg 'v'
  71. -- and should return true or false
  72. include_surrounding_whitespace = true,
  73. },
  74. },
  75. })
  76. end,
  77. },
  78. }