-
Notifications
You must be signed in to change notification settings - Fork 14
/
treesitter.lua
137 lines (137 loc) · 5.06 KB
/
treesitter.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
return {
{
"nvim-treesitter/nvim-treesitter-context",
dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" },
cmd = { "TSContextEnable", "TSContextDisable", "TSContextToggle" },
keys = {
{
"[C",
function()
require("treesitter-context").go_to_context(vim.v.count1)
end,
silent = true,
desc = "Goto treesitter context"
},
{
"]C",
function() require("treesitter-context").toggle() end,
silent = true,
desc = "Toggle treesitter context"
},
},
opts = {},
config = function()
require("treesitter-context").setup({ enable = true })
end,
enabled = true
},
{
"nvim-treesitter/nvim-treesitter",
-- treesitter requires a C compiler
cond = not require("utils").is_NetBSD() and require("utils").have_compiler,
event = "BufReadPost",
dependencies = {
"nvim-treesitter/nvim-treesitter-textobjects",
"nvim-treesitter/nvim-treesitter-context",
},
build = function()
-- build step is run independent of the condition
-- make sure we have treesitter before running ':TSUpdate'
if require("utils").have_compiler() then
vim.cmd("TSUpdate")
end
end,
config = function()
require "nvim-treesitter.configs".setup {
ensure_installed = {
"bash",
"c",
"cpp",
"go",
"javascript",
"typescript",
"json",
"jsonc",
"jsdoc",
"lua",
"python",
"rust",
"html",
"yaml",
"css",
"toml",
"markdown",
"markdown_inline",
"solidity",
"vimdoc",
-- for `nvim-treesitter/playground` / `:InspectTree`
"query",
},
highlight = { enable = true },
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<CR>",
node_incremental = "<CR>",
node_decremental = "<S-Tab>",
scope_incremental = "<Tab>",
},
},
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
["ac"] = { query = "@comment.outer", desc = "Select comment (outer)" },
["ic"] = { query = "@comment.inner", desc = "Select comment (inner)" },
["ao"] = { query = "@class.outer", desc = "Select class (outer)" },
["io"] = { query = "@class.inner", desc = "Select class (inner)" },
["af"] = { query = "@function.outer", desc = "Select function (outer)" },
["if"] = { query = "@function.inner", desc = "Select function (inner)" },
["ap"] = { query = "@parameter.outer", desc = "Select parameter (outer)" },
["ip"] = { query = "@parameter.inner", desc = "Select parameter (inner)" },
["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" }
},
selection_modes = {
-- default is charwise 'v'
["@parameter.inner"] = "v", -- charwise
["@parameter.outer"] = "v", -- charwise
["@function.inner"] = "V", -- linewise
["@function.outer"] = "V", -- linewise
["@class.inner"] = "V", -- linewise
["@class.outer"] = "V", -- linewise
["@scope"] = "v", -- charwise
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next = { -- jump to next start or end
["]f"] = { query = "@function.outer", desc = "Next function start|end" },
-- overrides next misspelled word
-- ["]s"] = { query = "@scope", query_group = "locals", desc = "Next scope" },
},
goto_previous = { -- jump to previous start or end
["[f"] = { query = "@function.outer", desc = "Previous function start" },
-- overrides previous misspelled word
-- ["[s"] = { query = "@scope", query_group = "locals", desc = "Previous scope" },
},
goto_next_start = {
["]F"] = { query = "@function.outer", desc = "Next function" },
["]p"] = { query = "@parameter.inner", desc = "Next parameter" },
},
goto_previous_start = {
["[F"] = { query = "@function.outer", desc = "Previous function" },
["[p"] = { query = "@parameter.inner", desc = "Previous parameter" },
},
},
},
}
-- repeat `]f` moves with `;,` disabled as doesn't fallback to normal `;,`
-- local ts_repeat_move = require "nvim-treesitter.textobjects.repeatable_move"
-- 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)
end,
}
}