config.nvim/lua/plugins/treesitter.lua

96 lines
3.4 KiB
Lua
Raw Normal View History

2023-04-13 10:54:07 +08:00
require("nvim-treesitter.configs").setup({
ensure_installed = {
"lua",
"gitignore",
"gitattributes",
"gitcommit",
"git_config",
"git_rebase",
"vim",
"vimdoc",
"query"
}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages
2023-04-13 10:54:07 +08:00
highlight = {
enable = true, -- false will disable the whole extension
additional_vim_regex_highlighting = true, -- git commit, etc.
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
2023-04-13 10:54:07 +08:00
},
indent = { enable = true },
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",
-- You can optionally set descriptions to the mappings (used in the desc parameter of
-- nvim_buf_set_keymap) which plugins like which-key display
["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
-- You can also use captures from other query groups like `locals.scm`
["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" },
},
selection_modes = {
['@parameter.outer'] = 'v', -- charwise
['@function.outer'] = 'V', -- linewise
['@class.outer'] = '<c-v>', -- blockwise
},
-- If you set this to `true` (default is `false`) then any textobject is
-- extended to include preceding or succeeding whitespace. Succeeding
-- whitespace has priority in order to act similarly to eg the built-in
-- `ap`.
--
-- Can also be a function which gets passed a table with the keys
-- * query_string: eg '@function.inner'
-- * selection_mode: eg 'v'
-- and should return true of false
include_surrounding_whitespace = true,
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
["]m"] = "@function.outer",
["]]"] = { query = "@class.outer", desc = "Next class start" },
["]o"] = "@loop.*",
["]z"] = { query = "@fold", query_group = "folds", desc = "Next fold" },
},
goto_next_end = {
["]M"] = "@function.outer",
["]["] = "@class.outer",
},
goto_previous_start = {
["[m"] = "@function.outer",
["[["] = "@class.outer",
["[o"] = "@loop.*",
["[z"] = { query = "@fold", query_group = "folds", desc = "Next fold" },
},
goto_previous_end = {
["[M"] = "@function.outer",
["[]"] = "@class.outer",
},
},
},
2023-04-13 10:54:07 +08:00
})
local ts_repeat_move = require "nvim-treesitter.textobjects.repeatable_move"
-- Repeat movement with ; and ,
-- vim way: ; goes to the direction you were moving.
vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move)
vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite)
-- Optionally, make builtin f, F, t, T also repeatable with ; and ,
vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f)
vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F)
vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t)
vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T)