147 lines
4.4 KiB
Lua
147 lines
4.4 KiB
Lua
-- Treesitter: Syntax highlighting, incremental selection, textobjects, autotag
|
|
return {
|
|
{
|
|
"nvim-treesitter/nvim-treesitter",
|
|
build = ":TSUpdate",
|
|
event = { "BufReadPost", "BufNewFile" },
|
|
dependencies = {
|
|
"nvim-treesitter/nvim-treesitter-textobjects",
|
|
"windwp/nvim-ts-autotag",
|
|
},
|
|
config = function()
|
|
require("nvim-treesitter.configs").setup({
|
|
-- Install parsers for primary languages
|
|
ensure_installed = {
|
|
"lua",
|
|
"vim",
|
|
"vimdoc",
|
|
"php",
|
|
"html",
|
|
"javascript",
|
|
"typescript",
|
|
"tsx",
|
|
"css",
|
|
"scss",
|
|
"json",
|
|
"markdown",
|
|
"markdown_inline",
|
|
"bash",
|
|
"regex",
|
|
},
|
|
|
|
-- Auto-install missing parsers
|
|
auto_install = true,
|
|
|
|
-- Syntax highlighting
|
|
highlight = {
|
|
enable = true,
|
|
-- Disable for very large files
|
|
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,
|
|
additional_vim_regex_highlighting = false,
|
|
},
|
|
|
|
-- Incremental selection
|
|
incremental_selection = {
|
|
enable = true,
|
|
keymaps = {
|
|
init_selection = "<CR>",
|
|
node_incremental = "<CR>",
|
|
scope_incremental = "<S-CR>",
|
|
node_decremental = "<BS>",
|
|
},
|
|
},
|
|
|
|
-- Indentation (experimental, disable if issues)
|
|
indent = {
|
|
enable = false, -- Start disabled; can enable per-filetype if stable
|
|
},
|
|
|
|
-- Textobjects
|
|
textobjects = {
|
|
select = {
|
|
enable = true,
|
|
lookahead = true, -- Jump forward to next textobject
|
|
keymaps = {
|
|
-- Functions
|
|
["af"] = "@function.outer",
|
|
["if"] = "@function.inner",
|
|
-- Classes
|
|
["ac"] = "@class.outer",
|
|
["ic"] = "@class.inner",
|
|
-- Parameters/arguments
|
|
["aa"] = "@parameter.outer",
|
|
["ia"] = "@parameter.inner",
|
|
-- Conditionals
|
|
["ai"] = "@conditional.outer",
|
|
["ii"] = "@conditional.inner",
|
|
-- Loops
|
|
["al"] = "@loop.outer",
|
|
["il"] = "@loop.inner",
|
|
-- Comments
|
|
["a/"] = "@comment.outer",
|
|
},
|
|
},
|
|
move = {
|
|
enable = true,
|
|
set_jumps = true, -- Add to jumplist
|
|
goto_next_start = {
|
|
["]f"] = "@function.outer",
|
|
["]c"] = "@class.outer",
|
|
["]a"] = "@parameter.inner",
|
|
},
|
|
goto_next_end = {
|
|
["]F"] = "@function.outer",
|
|
["]C"] = "@class.outer",
|
|
["]A"] = "@parameter.inner",
|
|
},
|
|
goto_previous_start = {
|
|
["[f"] = "@function.outer",
|
|
["[c"] = "@class.outer",
|
|
["[a"] = "@parameter.inner",
|
|
},
|
|
goto_previous_end = {
|
|
["[F"] = "@function.outer",
|
|
["[C"] = "@class.outer",
|
|
["[A"] = "@parameter.inner",
|
|
},
|
|
},
|
|
swap = {
|
|
enable = true,
|
|
swap_next = {
|
|
["<leader>a"] = "@parameter.inner",
|
|
},
|
|
swap_previous = {
|
|
["<leader>A"] = "@parameter.inner",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
-- Setup autotag
|
|
require("nvim-ts-autotag").setup({
|
|
opts = {
|
|
enable_close = true, -- Auto close tags
|
|
enable_rename = true, -- Auto rename pairs of tags
|
|
enable_close_on_slash = true, -- Auto close on trailing </
|
|
},
|
|
-- Limit to relevant filetypes
|
|
per_filetype = {
|
|
["html"] = { enable_close = true },
|
|
["php"] = { enable_close = true },
|
|
["javascript"] = { enable_close = true },
|
|
["javascriptreact"] = { enable_close = true },
|
|
["typescript"] = { enable_close = true },
|
|
["typescriptreact"] = { enable_close = true },
|
|
["vue"] = { enable_close = true },
|
|
},
|
|
})
|
|
end,
|
|
},
|
|
}
|