Skip to content

Commit 7f71925

Browse files
committed
added treesitter
1 parent 32efca6 commit 7f71925

5 files changed

Lines changed: 233 additions & 29 deletions

File tree

‎nvim-v12/README.md‎

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
# Neovim Configuration
2+
3+
This configuration is a **literate document**: the code lives here in `README.md`
4+
as fenced code blocks, and a script called `tangle.lua` extracts those blocks in
5+
order to produce `init.lua`, the file Neovim actually loads.
6+
7+
The idea is borrowed from the Emacs community (org-babel). Every plugin and
8+
setting has its explanation right next to the code, so the config stays readable
9+
even months later. GitHub renders this file for free. Never edit `init.lua`
10+
directly; this file is the single source of truth.
11+
12+
## How It Works
13+
14+
Every ` ```lua ` fenced block in this file gets extracted into `init.lua` in
15+
the order it appears. Blocks marked ` ```lua notangle ` are skipped: they
16+
display with syntax highlighting but are not included in the output. Use them
17+
for example code or temporarily disabled snippets.
18+
19+
Blocks marked ` ```sh install ` are extracted into `dependencies.sh`, a shell
20+
script you run once on a fresh machine to install all system dependencies.
21+
Each install block lives next to the section that needs it, so the reason for
22+
every dependency is always documented in context.
23+
24+
## Prerequisites
25+
26+
Install Neovim >= 0.11 manually. Ubuntu's apt version is too old; use the
27+
[official release](https://github.com/neovim/neovim/releases/latest).
28+
Everything else is handled by `dependencies.sh` after the first tangle.
29+
30+
```sh install
31+
# Core tools: git (lazy.nvim bootstrap), curl, gcc + make (parser/plugin builds)
32+
PKG git curl gcc make
33+
```
34+
35+
## Bootstrap
36+
37+
Install Neovim, clone this repo, then run three commands:
38+
39+
```sh
40+
git clone <your-repo-url> ~/.config/nvim
41+
nvim -l ~/.config/nvim/tangle.lua # generates init.lua + dependencies.sh
42+
bash ~/.config/nvim/dependencies.sh # installs ripgrep, fd, clangd, pylsp...
43+
nvim # plugins auto-install on first launch
44+
```
45+
46+
Saving this file inside Neovim re-tangles automatically. If you add a new
47+
dependency later, add an `sh install` block next to the relevant section and
48+
run `bash dependencies.sh` again. Already-installed packages are skipped.
49+
50+
After that, saving this file inside Neovim auto-tangles on every write.
51+
52+
---
53+
154
## Auto-Tangle on Save
255

356
When you save `README.md` inside Neovim this autocmd fires, runs `tangle.lua`,
@@ -502,6 +555,78 @@ vim.diagnostic.config({
502555
})
503556
```
504557

558+
### Treesitter
559+
560+
In nvim v0.12, treesitter now requires `tree-sitter-cli` as an external tool.
561+
562+
```sh install
563+
PKG tree-sitter-cli
564+
```
565+
566+
Setup autocmd to run `:TSUpdate` on `PackChanged`
567+
568+
```lua
569+
vim.api.nvim_create_autocmd('PackChanged', {
570+
callback = function(ev)
571+
if ev.data.spec.name == 'nvim-treesitter' then
572+
vim.schedule(function()
573+
vim.cmd('TSUpdate')
574+
end)
575+
end
576+
end,
577+
})
578+
```
579+
580+
Finally install treesitter.
581+
582+
```lua
583+
vim.pack.add({
584+
{
585+
src = 'https://github.com/nvim-treesitter/nvim-treesitter',
586+
version = 'main',
587+
},
588+
{
589+
src = 'https://github.com/nvim-treesitter/nvim-treesitter-textobjects',
590+
version = 'main',
591+
},
592+
{
593+
src = 'https://github.com/nvim-treesitter/nvim-treesitter-context',
594+
},
595+
})
596+
597+
nmap({'[x', function() require('treesitter-context').go_to_context() end })
598+
599+
local ensureInstalled = {
600+
"bash",
601+
"csv",
602+
"go",
603+
"gomod",
604+
"gowork",
605+
"gosum",
606+
"json",
607+
"ledger",
608+
"lua",
609+
"markdown",
610+
"markdown_inline",
611+
"python",
612+
}
613+
local alreadyInstalled = require('nvim-treesitter.config').get_installed()
614+
local toInstall = vim.iter(ensureInstalled)
615+
:filter(function(p) return not vim.tbl_contains(alreadyInstalled, p) end)
616+
:totable()
617+
require('nvim-treesitter').install(toInstall)
618+
```
619+
620+
Enable highlighting (replaces highlight = { enable = true })
621+
622+
```lua
623+
vim.api.nvim_create_autocmd('FileType', {
624+
callback = function()
625+
pcall(vim.treesitter.start)
626+
end,
627+
})
628+
```
629+
505630
## Telescope
506631

507632
Telescope is a pretty selector UI with some convenience functions built-in.

‎nvim-v12/dependencies.sh‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ else
1616
echo 'No supported package manager found (apt, pacman, brew).' >&2
1717
exit 1
1818
fi
19+
20+
# [Prerequisites]
21+
# Core tools: git (lazy.nvim bootstrap), curl, gcc + make (parser/plugin builds)
22+
PKG git curl gcc make
23+
24+
# [Treesitter]
25+
PKG tree-sitter-cli

‎nvim-v12/init.lua‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,61 @@ vim.diagnostic.config({
411411
},
412412
})
413413

414+
-- [Treesitter]
415+
vim.api.nvim_create_autocmd('PackChanged', {
416+
callback = function(ev)
417+
if ev.data.spec.name == 'nvim-treesitter' then
418+
vim.schedule(function()
419+
vim.cmd('TSUpdate')
420+
end)
421+
end
422+
end,
423+
})
424+
425+
-- [Treesitter]
426+
vim.pack.add({
427+
{
428+
src = 'https://github.com/nvim-treesitter/nvim-treesitter',
429+
version = 'main',
430+
},
431+
{
432+
src = 'https://github.com/nvim-treesitter/nvim-treesitter-textobjects',
433+
version = 'main',
434+
},
435+
{
436+
src = 'https://github.com/nvim-treesitter/nvim-treesitter-context',
437+
},
438+
})
439+
440+
nmap({'[x', function() require('treesitter-context').go_to_context() end })
441+
442+
local ensureInstalled = {
443+
"bash",
444+
"csv",
445+
"go",
446+
"gomod",
447+
"gowork",
448+
"gosum",
449+
"json",
450+
"ledger",
451+
"lua",
452+
"markdown",
453+
"markdown_inline",
454+
"python",
455+
}
456+
local alreadyInstalled = require('nvim-treesitter.config').get_installed()
457+
local toInstall = vim.iter(ensureInstalled)
458+
:filter(function(p) return not vim.tbl_contains(alreadyInstalled, p) end)
459+
:totable()
460+
require('nvim-treesitter').install(toInstall)
461+
462+
-- [Treesitter]
463+
vim.api.nvim_create_autocmd('FileType', {
464+
callback = function()
465+
pcall(vim.treesitter.start)
466+
end,
467+
})
468+
414469
-- [Telescope]
415470
vim.api.nvim_create_autocmd('PackChanged', {
416471
callback = function(ev)

‎nvim-v12/init.lua.map‎

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
-- Source map: init.lua line ranges → README.md section headings.
22
-- Generated by tangle.lua — do not edit directly.
33
return {
4-
{ init_start= 4, init_end= 14, readme_line= 1, section="Auto-Tangle on Save" },
5-
{ init_start= 17, init_end= 36, readme_line= 25, section="Editor Options" },
6-
{ init_start= 39, init_end= 48, readme_line= 60, section="Utilities" },
7-
{ init_start= 51, init_end= 82, readme_line= 78, section="Which-key" },
8-
{ init_start= 85, init_end= 85, readme_line=117, section="Mappings / Keybinds" },
9-
{ init_start= 88, init_end= 91, readme_line=117, section="Mappings / Keybinds" },
10-
{ init_start= 94, init_end= 96, readme_line=117, section="Mappings / Keybinds" },
11-
{ init_start= 99, init_end= 99, readme_line=117, section="Mappings / Keybinds" },
12-
{ init_start=102, init_end=107, readme_line=117, section="Mappings / Keybinds" },
13-
{ init_start=110, init_end=112, readme_line=117, section="Mappings / Keybinds" },
14-
{ init_start=115, init_end=119, readme_line=167, section="Theme" },
15-
{ init_start=122, init_end=310, readme_line=177, section="Status line" },
16-
{ init_start=313, init_end=315, readme_line=373, section="Navigate between tmux and nvim" },
17-
{ init_start=318, init_end=323, readme_line=383, section="Overseer" },
18-
{ init_start=326, init_end=335, readme_line=394, section="Notifications" },
19-
{ init_start=338, init_end=357, readme_line=410, section="LSP" },
20-
{ init_start=360, init_end=371, readme_line=410, section="LSP" },
21-
{ init_start=374, init_end=381, readme_line=410, section="LSP" },
22-
{ init_start=384, init_end=387, readme_line=410, section="LSP" },
23-
{ init_start=390, init_end=392, readme_line=474, section="Markdown renderer" },
24-
{ init_start=395, init_end=412, readme_line=474, section="Markdown renderer" },
25-
{ init_start=415, init_end=480, readme_line=505, section="Telescope" },
26-
{ init_start=483, init_end=555, readme_line=581, section="Telescope keymaps" },
27-
{ init_start=558, init_end=563, readme_line=659, section="Git" },
28-
{ init_start=566, init_end=582, readme_line=673, section="Git signs keymaps" },
29-
{ init_start=585, init_end=589, readme_line=695, section="Custom autocommands" },
30-
{ init_start=592, init_end=611, readme_line=695, section="Custom autocommands" },
31-
{ init_start=614, init_end=620, readme_line=695, section="Custom autocommands" },
32-
{ init_start=623, init_end=664, readme_line=695, section="Custom autocommands" },
4+
{ init_start= 4, init_end= 14, readme_line= 54, section="Auto-Tangle on Save" },
5+
{ init_start= 17, init_end= 36, readme_line= 78, section="Editor Options" },
6+
{ init_start= 39, init_end= 48, readme_line=113, section="Utilities" },
7+
{ init_start= 51, init_end= 82, readme_line=131, section="Which-key" },
8+
{ init_start= 85, init_end= 85, readme_line=170, section="Mappings / Keybinds" },
9+
{ init_start= 88, init_end= 91, readme_line=170, section="Mappings / Keybinds" },
10+
{ init_start= 94, init_end= 96, readme_line=170, section="Mappings / Keybinds" },
11+
{ init_start= 99, init_end= 99, readme_line=170, section="Mappings / Keybinds" },
12+
{ init_start=102, init_end=107, readme_line=170, section="Mappings / Keybinds" },
13+
{ init_start=110, init_end=112, readme_line=170, section="Mappings / Keybinds" },
14+
{ init_start=115, init_end=119, readme_line=220, section="Theme" },
15+
{ init_start=122, init_end=310, readme_line=230, section="Status line" },
16+
{ init_start=313, init_end=315, readme_line=426, section="Navigate between tmux and nvim" },
17+
{ init_start=318, init_end=323, readme_line=436, section="Overseer" },
18+
{ init_start=326, init_end=335, readme_line=447, section="Notifications" },
19+
{ init_start=338, init_end=357, readme_line=463, section="LSP" },
20+
{ init_start=360, init_end=371, readme_line=463, section="LSP" },
21+
{ init_start=374, init_end=381, readme_line=463, section="LSP" },
22+
{ init_start=384, init_end=387, readme_line=463, section="LSP" },
23+
{ init_start=390, init_end=392, readme_line=527, section="Markdown renderer" },
24+
{ init_start=395, init_end=412, readme_line=527, section="Markdown renderer" },
25+
{ init_start=415, init_end=423, readme_line=558, section="Treesitter" },
26+
{ init_start=426, init_end=460, readme_line=558, section="Treesitter" },
27+
{ init_start=463, init_end=467, readme_line=558, section="Treesitter" },
28+
{ init_start=470, init_end=535, readme_line=630, section="Telescope" },
29+
{ init_start=538, init_end=610, readme_line=706, section="Telescope keymaps" },
30+
{ init_start=613, init_end=618, readme_line=784, section="Git" },
31+
{ init_start=621, init_end=637, readme_line=798, section="Git signs keymaps" },
32+
{ init_start=640, init_end=644, readme_line=820, section="Custom autocommands" },
33+
{ init_start=647, init_end=666, readme_line=820, section="Custom autocommands" },
34+
{ init_start=669, init_end=675, readme_line=820, section="Custom autocommands" },
35+
{ init_start=678, init_end=719, readme_line=820, section="Custom autocommands" },
3336
}

‎nvim-v12/nvim-pack-lock.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@
3636
"rev": "8701bece920b38ea289b457f902e2ad184131a5d",
3737
"src": "https://github.com/rcarriga/nvim-notify"
3838
},
39+
"nvim-treesitter": {
40+
"rev": "4916d6592ede8c07973490d9322f187e07dfefac",
41+
"src": "https://github.com/nvim-treesitter/nvim-treesitter",
42+
"version": "'main'"
43+
},
44+
"nvim-treesitter-context": {
45+
"rev": "b0c45cefe2c8f7b55fc46f34e563bc428ef99636",
46+
"src": "https://github.com/nvim-treesitter/nvim-treesitter-context"
47+
},
48+
"nvim-treesitter-textobjects": {
49+
"rev": "851e865342e5a4cb1ae23d31caf6e991e1c99f1e",
50+
"src": "https://github.com/nvim-treesitter/nvim-treesitter-textobjects",
51+
"version": "'main'"
52+
},
3953
"nvim-web-devicons": {
4054
"rev": "c72328a5494b4502947a022fe69c0c47e53b6aa6",
4155
"src": "https://github.com/nvim-tree/nvim-web-devicons"

0 commit comments

Comments
 (0)