123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- local status, treesitter = pcall(require, "nvim-treesitter.configs")
- if not status then
- vim.notify("没有找到 nvim-treesitter")
- return
- end
- require("nvim-treesitter.install").prefer_git = true
- treesitter.setup({
- sync_install = false,
- -- 安装 language parser
- -- :TSInstallInfo 命令查看支持的语言
- -- ensure_installed = { "json", "html", "css", "vim", "lua", "javascript", "typescript", "tsx", "markdown" },
- -- ensure_installed = "maintained",
- -- 启用代码高亮模块
- highlight = {
- enable = true,
- additional_vim_regex_highlighting = false,
- disable = function(lang, bufnr) -- Disable in large C++ buffers
- return vim.api.nvim_buf_line_count(bufnr) > 10000
- end,
- },
- -- 启用增量选择模块
- incremental_selection = {
- enable = false,
- keymaps = {
- init_selection = "<CR>",
- node_incremental = "<CR>",
- node_decremental = "<BS>",
- scope_incremental = "<TAB>",
- },
- },
- -- 启用代码缩进模块 (=)
- indent = {
- enable = true,
- },
- -- p00f/nvim-ts-rainbow
- rainbow = {
- enable = true,
- -- disable = { "jsx", "cpp" }, list of languages you want to disable the plugin for
- extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean
- max_file_lines = 10000, -- Do not enable for files with more than n lines, int
- colors = {
- "#95ca60",
- "#ee6985",
- "#D6A760",
- "#7794f4",
- "#b38bf5",
- "#7cc7fe",
- }, -- table of hex strings
- -- termcolors = { } -- table of colour name strings
- },
- -- https://github.com/JoosepAlviste/nvim-ts-context-commentstring
- context_commentstring = {
- enable = true,
- enable_autocmd = false,
- },
- -- https://github.com/windwp/nvim-ts-autotag
- autotag = {
- enable = true,
- },
- -- nvim-treesitter/nvim-treesitter-refactor
- refactor = {
- highlight_definitions = {
- enable = true,
- -- Set to false if you have an `updatetime` of ~100.
- clear_on_cursor_move = true,
- },
- highlight_current_scope = { enable = true },
- },
- -- nvim-treesitter/nvim-treesitter-textobjects
- textobjects = {
- select = {
- enable = true,
- -- Automatically jump forward to textobj, similar to targets.vim
- lookahead = true,
- keymaps = {
- -- You can use the capture groups defined in textobjects.scm
- ["af"] = "@function.outer",
- ["if"] = "@function.inner",
- ["ac"] = "@class.outer",
- ["ic"] = "@class.inner",
- ["ai"] = "@conditional.outer",
- ["ii"] = "@conditional.inner",
- ["al"] = "@loop.outer",
- ["il"] = "@loop.inner",
- ["ab"] = "@block.outer",
- ["ib"] = "@block.inner",
- },
- },
- swap = {
- enable = false,
- swap_next = {
- ["<leader>a"] = "@parameter.inner",
- },
- swap_previous = {
- ["<leader>A"] = "@parameter.inner",
- },
- },
- move = {
- enable = true,
- set_jumps = true, -- whether to set jumps in the jumplist
- goto_next_start = {
- ["]m"] = "@function.outer",
- ["]]"] = "@class.outer",
- },
- goto_next_end = {
- ["]M"] = "@function.outer",
- ["]["] = "@class.outer",
- },
- goto_previous_start = {
- ["[m"] = "@function.outer",
- ["[["] = "@class.outer",
- },
- goto_previous_end = {
- ["[M"] = "@function.outer",
- ["[]"] = "@class.outer",
- },
- },
- },
- })
- -- 开启 Folding 模块
- vim.opt.foldmethod = "expr"
- vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
- -- 默认不要折叠
- -- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file
- vim.opt.foldlevel = 99
|