treesitter.lua 2.4 KB

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