initial commit
This commit is contained in:
81
lua/plugins/treesitter.lua
Normal file
81
lua/plugins/treesitter.lua
Normal file
@ -0,0 +1,81 @@
|
||||
vim.api.nvim_create_autocmd('PackChanged', {
|
||||
callback = function(ev)
|
||||
local name, kind = ev.data.spec.name, ev.data.kind
|
||||
if name == 'nvim-treesitter' and kind == 'update' then
|
||||
if not ev.data.active then vim.cmd.packadd('nvim-treesitter') end
|
||||
vim.cmd(':TSUpdate')
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
vim.pack.add(
|
||||
{ { src = "https://github.com/nvim-treesitter/nvim-treesitter", version = "main" } }
|
||||
)
|
||||
|
||||
local ts = require('nvim-treesitter')
|
||||
ts.setup {
|
||||
-- Directory to install parsers and queries to (prepended to `runtimepath` to have priority)
|
||||
install_dir = vim.fn.stdpath('data') .. '/site',
|
||||
highlight = {
|
||||
enable = true,
|
||||
additional_vim_regex_highlighting = false,
|
||||
},
|
||||
indent = { enable = false },
|
||||
}
|
||||
|
||||
local languages =
|
||||
{
|
||||
"bash",
|
||||
"c",
|
||||
"diff",
|
||||
"html",
|
||||
"javascript",
|
||||
"json",
|
||||
"lua",
|
||||
"markdown",
|
||||
"markdown_inline",
|
||||
"python",
|
||||
"query",
|
||||
"regex",
|
||||
"rust",
|
||||
"toml",
|
||||
"vim",
|
||||
"vimdoc",
|
||||
"yaml",
|
||||
"wgsl",
|
||||
}
|
||||
|
||||
ts.install(languages):wait(300000)
|
||||
|
||||
for _, lang in pairs(languages) do
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = { lang },
|
||||
callback = function() vim.treesitter.start() end,
|
||||
})
|
||||
end
|
||||
|
||||
-- Incremental selection keybindings
|
||||
vim.keymap.set({ 'x' }, '<c-p>', function()
|
||||
require 'vim.treesitter._select'.select_prev(vim.v.count1)
|
||||
end, { desc = 'Select previous treesitter node' })
|
||||
|
||||
vim.keymap.set({ 'x' }, '<c-n>', function()
|
||||
require 'vim.treesitter._select'.select_next(vim.v.count1)
|
||||
end, { desc = 'Select next treesitter node' })
|
||||
|
||||
vim.keymap.set({ 'x', 'o' }, 'v', function()
|
||||
if vim.treesitter.get_parser(nil, nil, { error = false }) then
|
||||
require 'vim.treesitter._select'.select_parent(vim.v.count1)
|
||||
else
|
||||
vim.lsp.buf.selection_range(vim.v.count1)
|
||||
end
|
||||
end, { desc = 'Select parent treesitter node or outer incremental lsp selections' })
|
||||
|
||||
vim.keymap.set({ 'x', 'o' }, 'V', function()
|
||||
if vim.treesitter.get_parser(nil, nil, { error = false }) then
|
||||
require 'vim.treesitter._select'.select_child(vim.v.count1)
|
||||
else
|
||||
vim.lsp.buf.selection_range(-vim.v.count1)
|
||||
end
|
||||
end, { desc = 'Select child treesitter node or inner incremental lsp selections' })
|
||||
|
||||
Reference in New Issue
Block a user