treesitter.lua 2.5 KB

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