nvim-treesitter.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. local status, treesitter = pcall(require, "nvim-treesitter.configs")
  2. if not status then
  3. vim.notify("没有找到 nvim-treesitter")
  4. return
  5. end
  6. require("nvim-treesitter.install").prefer_git = true
  7. treesitter.setup({
  8. sync_install = false,
  9. -- 安装 language parser
  10. -- :TSInstallInfo 命令查看支持的语言
  11. -- ensure_installed = { "json", "html", "css", "vim", "lua", "javascript", "typescript", "tsx", "markdown" },
  12. -- ensure_installed = "maintained",
  13. -- 启用代码高亮模块
  14. highlight = {
  15. enable = true,
  16. additional_vim_regex_highlighting = false,
  17. disable = function(lang, bufnr) -- Disable in large C++ buffers
  18. return vim.api.nvim_buf_line_count(bufnr) > 10000
  19. end,
  20. },
  21. -- 启用增量选择模块
  22. incremental_selection = {
  23. enable = false,
  24. keymaps = {
  25. init_selection = "<CR>",
  26. node_incremental = "<CR>",
  27. node_decremental = "<BS>",
  28. scope_incremental = "<TAB>",
  29. },
  30. },
  31. -- 启用代码缩进模块 (=)
  32. indent = {
  33. enable = true,
  34. },
  35. -- p00f/nvim-ts-rainbow
  36. rainbow = {
  37. enable = true,
  38. -- disable = { "jsx", "cpp" }, list of languages you want to disable the plugin for
  39. extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean
  40. max_file_lines = 10000, -- Do not enable for files with more than n lines, int
  41. colors = {
  42. "#95ca60",
  43. "#ee6985",
  44. "#D6A760",
  45. "#7794f4",
  46. "#b38bf5",
  47. "#7cc7fe",
  48. }, -- table of hex strings
  49. -- termcolors = { } -- table of colour name strings
  50. },
  51. -- https://github.com/JoosepAlviste/nvim-ts-context-commentstring
  52. context_commentstring = {
  53. enable = true,
  54. enable_autocmd = false,
  55. },
  56. -- https://github.com/windwp/nvim-ts-autotag
  57. autotag = {
  58. enable = true,
  59. },
  60. -- nvim-treesitter/nvim-treesitter-refactor
  61. refactor = {
  62. highlight_definitions = {
  63. enable = true,
  64. -- Set to false if you have an `updatetime` of ~100.
  65. clear_on_cursor_move = true,
  66. },
  67. highlight_current_scope = { enable = true },
  68. },
  69. -- nvim-treesitter/nvim-treesitter-textobjects
  70. textobjects = {
  71. select = {
  72. enable = true,
  73. -- Automatically jump forward to textobj, similar to targets.vim
  74. lookahead = true,
  75. keymaps = {
  76. -- You can use the capture groups defined in textobjects.scm
  77. ["af"] = "@function.outer",
  78. ["if"] = "@function.inner",
  79. ["ac"] = "@class.outer",
  80. ["ic"] = "@class.inner",
  81. ["ai"] = "@conditional.outer",
  82. ["ii"] = "@conditional.inner",
  83. ["al"] = "@loop.outer",
  84. ["il"] = "@loop.inner",
  85. ["ab"] = "@block.outer",
  86. ["ib"] = "@block.inner",
  87. },
  88. },
  89. swap = {
  90. enable = false,
  91. swap_next = {
  92. ["<leader>a"] = "@parameter.inner",
  93. },
  94. swap_previous = {
  95. ["<leader>A"] = "@parameter.inner",
  96. },
  97. },
  98. move = {
  99. enable = true,
  100. set_jumps = true, -- whether to set jumps in the jumplist
  101. goto_next_start = {
  102. ["]m"] = "@function.outer",
  103. ["]]"] = "@class.outer",
  104. },
  105. goto_next_end = {
  106. ["]M"] = "@function.outer",
  107. ["]["] = "@class.outer",
  108. },
  109. goto_previous_start = {
  110. ["[m"] = "@function.outer",
  111. ["[["] = "@class.outer",
  112. },
  113. goto_previous_end = {
  114. ["[M"] = "@function.outer",
  115. ["[]"] = "@class.outer",
  116. },
  117. },
  118. },
  119. })
  120. -- 开启 Folding 模块
  121. vim.opt.foldmethod = "expr"
  122. vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
  123. -- 默认不要折叠
  124. -- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file
  125. vim.opt.foldlevel = 99