diff --git a/nvim/.config/nvim/README.md b/nvim/.config/nvim/README.md index 67f66ff..c309ae3 100644 --- a/nvim/.config/nvim/README.md +++ b/nvim/.config/nvim/README.md @@ -62,12 +62,30 @@ Open a terminal in a vertical split: Leave terminal mode and return to normal mode: -```vim - -``` - -In this config, `` in terminal mode is mapped to the same command: - ```vim ``` + + +## Tree-sitter + +Tree-sitter is managed with `nvim-treesitter` via `vim.pack`. + +Installing missing parsers requires the external tools from the upstream README: + +- `tar` +- `curl` +- `tree-sitter-cli` +- a C compiler + +If `tree-sitter` is on your `PATH`, startup will try to install the configured parsers if they are missing. + +Useful commands: + +```vim +:TSUpdate +:TSInstall lua bash json +:TSInstallInfo +:InspectTree +:checkhealth vim.treesitter +``` diff --git a/nvim/.config/nvim/lua/romanzy/plugins.lua b/nvim/.config/nvim/lua/romanzy/plugins.lua index 8795cf6..3ae6e93 100644 --- a/nvim/.config/nvim/lua/romanzy/plugins.lua +++ b/nvim/.config/nvim/lua/romanzy/plugins.lua @@ -1 +1,2 @@ require("romanzy.plugins.rose-pine") +require("romanzy.plugins.nvim-treesitter") diff --git a/nvim/.config/nvim/lua/romanzy/plugins/nvim-treesitter.lua b/nvim/.config/nvim/lua/romanzy/plugins/nvim-treesitter.lua new file mode 100644 index 0000000..dc07cc6 --- /dev/null +++ b/nvim/.config/nvim/lua/romanzy/plugins/nvim-treesitter.lua @@ -0,0 +1,56 @@ +local parsers = { + "bash", + "c", + "gitcommit", + "javascript", + "json", + "lua", + "markdown", + "python", + "toml", + "typescript", + "vim", + "vimdoc", + "yaml", +} + +local filetypes = { + "bash", + "c", + "gitcommit", + "javascript", + "json", + "lua", + "markdown", + "python", + "sh", + "toml", + "typescript", + "vim", + "vimdoc", + "yaml", +} + +vim.pack.add({ + { + src = "https://github.com/nvim-treesitter/nvim-treesitter", + name = "nvim-treesitter", + }, +}) + +require("nvim-treesitter").setup({ + install_dir = vim.fn.stdpath("data") .. "/site", +}) + +vim.treesitter.language.register("bash", { "sh" }) + +if vim.fn.executable("tree-sitter") == 1 then + require("nvim-treesitter").install(parsers) +end + +vim.api.nvim_create_autocmd("FileType", { + pattern = filetypes, + callback = function(ev) + pcall(vim.treesitter.start, ev.buf) + end, +}) diff --git a/nvim/.config/nvim/nvim-pack-lock.json b/nvim/.config/nvim/nvim-pack-lock.json index 4bb5722..49a2fd5 100644 --- a/nvim/.config/nvim/nvim-pack-lock.json +++ b/nvim/.config/nvim/nvim-pack-lock.json @@ -1,5 +1,9 @@ { "plugins": { + "nvim-treesitter": { + "rev": "4916d6592ede8c07973490d9322f187e07dfefac", + "src": "https://github.com/nvim-treesitter/nvim-treesitter" + }, "rose-pine": { "rev": "ff483051a47e27d84bdef47703538df1ed9f4a47", "src": "https://github.com/rose-pine/neovim"