mirror of
https://github.com/gyoder/dots.git
synced 2026-04-02 20:25:46 +00:00
Compare commits
2 commits
668326d54b
...
8246ae5804
| Author | SHA1 | Date | |
|---|---|---|---|
| 8246ae5804 | |||
| a870e9610a |
2 changed files with 145 additions and 13 deletions
|
|
@ -24,28 +24,155 @@ return require("packed").setup(function(use)
|
|||
end,
|
||||
}
|
||||
|
||||
|
||||
-- https://tduyng.com/blog/neovim-highlight-syntax/
|
||||
use {
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
branch = 'main',
|
||||
config = function()
|
||||
require('nvim-treesitter').setup()
|
||||
local parser_path = vim.fn.expand("~/.local/share/nvim/site/parser")
|
||||
vim.opt.runtimepath:append(parser_path)
|
||||
|
||||
require('nvim-treesitter').install({
|
||||
'c', 'lua', 'vim', 'vimdoc', 'query', 'markdown', 'markdown_inline', 'go'
|
||||
}):wait()
|
||||
require("nvim-treesitter").setup({})
|
||||
require("nvim-treesitter").install({
|
||||
"bash",
|
||||
"blade",
|
||||
"c",
|
||||
"comment",
|
||||
"css",
|
||||
"diff",
|
||||
"dockerfile",
|
||||
"fish",
|
||||
"gitcommit",
|
||||
"gitignore",
|
||||
"go",
|
||||
"gomod",
|
||||
"gosum",
|
||||
"gowork",
|
||||
"html",
|
||||
"ini",
|
||||
"javascript",
|
||||
"jsdoc",
|
||||
"json",
|
||||
"lua",
|
||||
"luadoc",
|
||||
"luap",
|
||||
"make",
|
||||
"markdown",
|
||||
"markdown_inline",
|
||||
"nginx",
|
||||
"nix",
|
||||
"proto",
|
||||
"python",
|
||||
"query",
|
||||
"regex",
|
||||
"rust",
|
||||
"scss",
|
||||
"sql",
|
||||
"terraform",
|
||||
"toml",
|
||||
"tsx",
|
||||
"typescript",
|
||||
"vim",
|
||||
"vimdoc",
|
||||
"xml",
|
||||
"yaml",
|
||||
"zig",
|
||||
})
|
||||
|
||||
-- enable highlighting
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
callback = function(args)
|
||||
local max_filesize = 100 * 1024 -- 100 KB
|
||||
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(args.buf))
|
||||
if ok and stats and stats.size > max_filesize then
|
||||
return
|
||||
vim.api.nvim_create_autocmd("PackChanged", {
|
||||
desc = "Handle nvim-treesitter updates",
|
||||
group = vim.api.nvim_create_augroup("nvim-treesitter-pack-changed-update-handler", { clear = true }),
|
||||
callback = function(event)
|
||||
if event.data.kind == "update" then
|
||||
local ok = pcall(vim.cmd, "TSUpdate")
|
||||
if ok then
|
||||
vim.notify("TSUpdate completed successfully!", vim.log.levels.INFO)
|
||||
else
|
||||
vim.notify("TSUpdate command not available yet, skipping", vim.log.levels.WARN)
|
||||
end
|
||||
end
|
||||
pcall(vim.treesitter.start)
|
||||
end,
|
||||
})
|
||||
|
||||
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = { "*" },
|
||||
callback = function()
|
||||
local filetype = vim.bo.filetype
|
||||
if filetype and filetype ~= "" then
|
||||
local success = pcall(function()
|
||||
vim.treesitter.start()
|
||||
end)
|
||||
if not success then
|
||||
return
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
}
|
||||
|
||||
use {
|
||||
src = "https://github.com/nvim-treesitter/nvim-treesitter-textobjects",
|
||||
version = "main",
|
||||
config = function()
|
||||
require("nvim-treesitter-textobjects").setup({
|
||||
select = {
|
||||
enable = true,
|
||||
lookahead = true,
|
||||
selection_modes = {
|
||||
["@parameter.outer"] = "v", -- charwise
|
||||
["@function.outer"] = "V", -- linewise
|
||||
["@class.outer"] = "<c-v>", -- blockwise
|
||||
},
|
||||
include_surrounding_whitespace = false,
|
||||
},
|
||||
move = {
|
||||
enable = true,
|
||||
set_jumps = true,
|
||||
},
|
||||
})
|
||||
|
||||
-- SELECT keymaps
|
||||
local sel = require("nvim-treesitter-textobjects.select")
|
||||
for _, map in ipairs({
|
||||
{ { "x", "o" }, "af", "@function.outer" },
|
||||
{ { "x", "o" }, "if", "@function.inner" },
|
||||
{ { "x", "o" }, "ac", "@class.outer" },
|
||||
{ { "x", "o" }, "ic", "@class.inner" },
|
||||
{ { "x", "o" }, "aa", "@parameter.outer" },
|
||||
{ { "x", "o" }, "ia", "@parameter.inner" },
|
||||
{ { "x", "o" }, "ad", "@comment.outer" },
|
||||
{ { "x", "o" }, "as", "@statement.outer" },
|
||||
}) do
|
||||
vim.keymap.set(map[1], map[2], function()
|
||||
sel.select_textobject(map[3], "textobjects")
|
||||
end, { desc = "Select " .. map[3] })
|
||||
end
|
||||
|
||||
-- MOVE keymaps
|
||||
local mv = require("nvim-treesitter-textobjects.move")
|
||||
for _, map in ipairs({
|
||||
{ { "n", "x", "o" }, "]]", mv.goto_next_start, "@function.outer" },
|
||||
{ { "n", "x", "o" }, "[[", mv.goto_previous_start, "@function.outer" },
|
||||
{ { "n", "x", "o" }, "]f", mv.goto_next_start, "@function.outer" },
|
||||
{ { "n", "x", "o" }, "[f", mv.goto_previous_start, "@function.outer" },
|
||||
{ { "n", "x", "o" }, "]c", mv.goto_next_start, "@class.outer" },
|
||||
{ { "n", "x", "o" }, "[c", mv.goto_previous_start, "@class.outer" },
|
||||
{ { "n", "x", "o" }, "]F", mv.goto_next_end, "@function.outer" },
|
||||
{ { "n", "x", "o" }, "[F", mv.goto_previous_end, "@function.outer" },
|
||||
{ { "n", "x", "o" }, "]o", mv.goto_next_start, { "@loop.inner", "@loop.outer" } },
|
||||
{ { "n", "x", "o" }, "[o", mv.goto_previous_start, { "@loop.inner", "@loop.outer" } },
|
||||
}) do
|
||||
local modes, lhs, fn, query = map[1], map[2], map[3], map[4]
|
||||
-- build a human-readable desc
|
||||
local qstr = (type(query) == "table") and table.concat(query, ",") or query
|
||||
vim.keymap.set(modes, lhs, function()
|
||||
fn(query, "textobjects")
|
||||
end, { desc = "Move to " .. qstr })
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,11 @@
|
|||
"src": "https://github.com/nvim-treesitter/nvim-treesitter",
|
||||
"version": "'main'"
|
||||
},
|
||||
"nvim-treesitter-textobjects": {
|
||||
"rev": "93d60a475f0b08a8eceb99255863977d3a25f310",
|
||||
"src": "https://github.com/nvim-treesitter/nvim-treesitter-textobjects",
|
||||
"version": "'main'"
|
||||
},
|
||||
"nvim-web-devicons": {
|
||||
"rev": "d7462543c9e366c0d196c7f67a945eaaf5d99414",
|
||||
"src": "https://github.com/nvim-tree/nvim-web-devicons"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue