AST implementation for neovim text editor.
- Abstract Syntax Tree (AST), is a tree that represents the code in an abstract way, which will help you understand the code better.
- Especially when you are working on someone else's codebase
- It's also helpful to move around in a file quickly
- Install NerdFont for displaying icons in right format.
- Treesitter plugin
- Plenary plugin (optional, for popup UI)
- (Optional) Telescope for enhanced search
Using your favorite plugin manager, install this plugin with its dependencies.
Here is an example for packer package manager.
use{
"ydkulks/AST.nvim",
requires = {
"nvim-treesitter/nvim-treesitter",
"nvim-lua/plenary.nvim"
},
config = function()
require("AST")
end
}Type :ASTToggle in vim command-line to open the AST window. If Plenary is available, it opens a popup window; otherwise, it falls back to the quickfix list.
- Navigate to the node you want to jump to and press
<CR> - Press
qto close the window
- Navigate to the node you want to jump to and press
<CR> - This jumps to the code location and closes the quickfix window
- Use
:ccloseto close without jumping
Type :ASTSearch to populate the quickfix list and open Telescope's fuzzy search (if available) or the standard quickfix window.
- Use Telescope's search to filter and select nodes
- Press
<CR>to jump to the selected node
You can view the defaults here and customize them according to your needs
The plugin can be configured using the setup() function. Available options:
displayNodeNames:trueto show node names (e.g., function names),falseto show node types (default:true)nodeTypeRequired: Buffer type (key) and a table of nodes and their icons
Example configuration:
require("AST").setup({
displayNodeNames = true,
nodeTypeRequired = {
rust = {
{ "function_declaration", " " },
{ "if_statement", " " },
{ "for_statement", " " },
{ "while_statement", " " }
}
}
})Note: You can get the node type value from inspecting the buffer using
:InspectTreeor by installing treesitter's playground plugin.
Map the commands to keys for quick access.
-- For example:
-- Mapped <leader>t to toggle the AST window
vim.keymap.set("n","<leader>t",":ASTToggle<CR>")
-- Mapped <leader>s to search AST nodes
vim.keymap.set("n","<leader>s",":ASTSearch<CR>")In this file,
some highlight groups have been created. Which can be changed in your configuration.
-- Here is an example to configure highlight groups
vim.api.nvim_set_hl(0, 'ASTIcon', { fg = "#98C379", ctermfg = 114 })- Submissions are welcome. Just open a pull-request under a branch named after your name.
- DO NOT MAKE CHANGES TO MAIN BRANCH
- If you find a bug, please create an issue.


