aerial.nvim/README.md

594 lines
19 KiB
Markdown
Raw Normal View History

2020-09-20 00:59:51 +02:00
# aerial.nvim
2022-01-02 01:05:51 +01:00
2021-06-16 17:48:32 +02:00
A code outline window for skimming and quick navigation
2020-09-20 02:29:26 +02:00
2022-10-21 21:26:47 +02:00
<!-- TOC -->
2022-01-02 01:05:51 +01:00
- [Requirements](#requirements)
- [Installation](#installation)
- [Setup](#setup)
- [Commands](#commands)
- [Options](#options)
- [Third-party integrations](#third-party-integrations)
- [Telescope](#telescope)
2022-10-21 21:26:47 +02:00
- [fzf](#fzf)
2022-01-02 01:05:51 +01:00
- [Lualine](#lualine)
- [Highlight](#highlight)
2022-10-21 21:26:47 +02:00
- [API](#api)
2022-01-02 01:05:51 +01:00
- [FAQ](#faq)
2022-10-21 21:26:47 +02:00
<!-- /TOC -->
2021-06-19 20:56:15 +02:00
https://user-images.githubusercontent.com/506791/122652728-18688500-d0f5-11eb-80aa-910f7e6a5f46.mp4
2020-09-20 02:29:26 +02:00
## Requirements
2022-01-02 01:05:51 +01:00
- Neovim 0.8+ (for older versions, use the [nvim-0.5 branch](https://github.com/stevearc/aerial.nvim/tree/nvim-0.5))
2022-01-02 01:05:51 +01:00
- One or more of the following:
- A working LSP setup (see [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig))
- [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) with languages installed
2020-09-20 02:29:26 +02:00
## Installation
2022-01-02 01:05:51 +01:00
aerial supports all the usual plugin managers
2020-09-20 02:29:26 +02:00
<details>
<summary>Packer</summary>
2020-09-20 02:29:26 +02:00
2022-01-02 01:05:51 +01:00
```lua
require('packer').startup(function()
use {
'stevearc/aerial.nvim',
config = function() require('aerial').setup() end
}
2022-01-02 01:05:51 +01:00
end)
```
</details>
2020-09-20 02:29:26 +02:00
<details>
<summary>Paq</summary>
2022-01-02 01:05:51 +01:00
```lua
require "paq" {
{'stevearc/aerial.nvim'};
}
```
</details>
<details>
<summary>vim-plug</summary>
2022-01-02 01:05:51 +01:00
```vim
Plug 'stevearc/aerial.nvim'
```
</details>
<details>
<summary>dein</summary>
2022-01-02 01:05:51 +01:00
```vim
call dein#add('stevearc/aerial.nvim')
```
</details>
<details>
<summary>Pathogen</summary>
2022-01-02 01:05:51 +01:00
```sh
git clone --depth=1 https://github.com/stevearc/aerial.nvim.git ~/.vim/bundle/
```
</details>
<details>
<summary>Neovim native package</summary>
2022-01-02 01:05:51 +01:00
```sh
git clone --depth=1 https://github.com/stevearc/aerial.nvim.git \
"${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/aerial/start/aerial.nvim
```
</details>
2020-09-20 02:29:26 +02:00
## Setup
2022-01-02 01:05:51 +01:00
Somewhere in your init.lua you will need to call `aerial.setup()`. See below for
[a full list of options](#options).
```lua
2022-10-21 21:26:47 +02:00
require('aerial').setup({
-- optionally use on_attach to set keymaps when aerial has attached to a buffer
on_attach = function(bufnr)
-- Jump forwards/backwards with '{' and '}'
vim.keymap.set('n', '{', '<cmd>AerialPrev<CR>', {buffer = bufnr})
vim.keymap.set('n', '}', '<cmd>AerialNext<CR>', {buffer = bufnr})
end
})
-- You probably also want to set a keymap to toggle aerial
vim.keymap.set('n', '<leader>a', '<cmd>AerialToggle!<CR>')
```
In addition, you will need to have either Treesitter or a working LSP client. You can configure your preferred source(s) with the `backends` option (see [Options](#options)). The default is to prefer Treesitter when it's available and fall back to LSP.
<details>
<summary>Supported treesitter languages</summary>
2022-01-02 01:05:51 +01:00
- bash
- c
- c_sharp
- cpp
- dart
2022-06-23 17:47:42 +02:00
- elixir
2022-01-02 01:05:51 +01:00
- go
- help
2022-01-02 01:05:51 +01:00
- java
- javascript
- json
- julia
2022-01-02 01:05:51 +01:00
- lua
- make
2022-01-02 01:05:51 +01:00
- markdown
- norg
2022-04-17 09:56:25 +02:00
- org
- php
2022-08-29 14:38:51 +02:00
- proto
2022-01-02 01:05:51 +01:00
- python
- rst
- ruby
- rust
- scala
- teal
- tsx
2022-01-02 01:05:51 +01:00
- typescript
- vim
- yaml
Don't see your language here? [Request support for
it](https://github.com/stevearc/aerial.nvim/issues/new?assignees=stevearc&labels=enhancement&template=feature-request--treesitter-language-.md&title=)
2022-01-02 01:05:51 +01:00
</details>
2022-10-21 21:26:47 +02:00
## Commands
2020-09-20 02:29:26 +02:00
2022-10-21 21:26:47 +02:00
| Command | Args | Description |
| -------------------- | ------------------ | ------------------------------------------------------------------------ |
| `AerialToggle[!]` | `left/right/float` | Open or close the aerial window. With `!` cursor stays in current window |
| `AerialOpen[!]` | `left/right/float` | Open the aerial window. With `!` cursor stays in current window |
| `AerialOpenAll` | | Open an aerial window for each visible window. |
| `AerialClose` | | Close the aerial window. |
| `AerialCloseAll` | | Close all visible aerial windows. |
| `[count]AerialNext` | | Jump forwards {count} symbols (default 1). |
| `[count]AerialPrev` | | Jump backwards [count] symbols (default 1). |
| `[count]AerialGo[!]` | | Jump to the [count] symbol (default 1). |
| `AerialInfo` | | Print out debug info related to aerial. |
2020-09-20 02:29:26 +02:00
2021-06-17 20:10:54 +02:00
## Options
```lua
2022-01-02 01:05:51 +01:00
-- Call the setup function to change the default behavior
require("aerial").setup({
-- Priority list of preferred backends for aerial.
-- This can be a filetype map (see :help aerial-filetype-map)
backends = { "treesitter", "lsp", "markdown", "man" },
layout = {
-- These control the width of the aerial window.
-- They can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
-- min_width and max_width can be a list of mixed types.
-- max_width = {40, 0.2} means "the lesser of 40 columns or 20% of total"
max_width = { 40, 0.2 },
width = nil,
min_width = 10,
-- Determines the default direction to open the aerial window. The 'prefer'
-- options will open the window in the other direction *if* there is a
-- different buffer in the way of the preferred direction
-- Enum: prefer_right, prefer_left, right, left, float
default_direction = "prefer_right",
-- Determines where the aerial window will be opened
-- edge - open aerial at the far right/left of the editor
-- window - open aerial to the right/left of the current window
placement = "window",
},
-- Determines how the aerial window decides which buffer to display symbols for
-- window - aerial window will display symbols for the buffer in the window from which it was opened
-- global - aerial window will display symbols for the current window
attach_mode = "window",
-- List of enum values that configure when to auto-close the aerial window
-- unfocus - close aerial when you leave the original source window
-- switch_buffer - close aerial when you change buffers in the source window
-- unsupported - close aerial when attaching to a buffer that has no symbol source
close_automatic_events = {},
2021-06-18 02:06:21 +02:00
2022-10-21 21:26:47 +02:00
-- Keymaps in aerial window. Can be any value that `vim.keymap.set` accepts.
-- Additionally, if it is a string that matches "aerial.<name>",
-- it will use the function at require("aerial.action").<name>
-- Set to `false` to remove a keymap
keymaps = {
["?"] = "actions.show_help",
["g?"] = "actions.show_help",
["<CR>"] = "actions.jump",
["<2-LeftMouse>"] = "actions.jump",
["<C-v>"] = "actions.jump_vsplit",
["<C-s>"] = "actions.jump_split",
["p"] = "actions.scroll",
["<C-j>"] = "actions.down_and_scroll",
["<C-k>"] = "actions.up_and_scroll",
["{"] = "actions.prev",
["}"] = "actions.next",
["[["] = "actions.prev_up",
["]]"] = "actions.next_up",
["q"] = "actions.close",
["o"] = "actions.tree_toggle",
["za"] = "actions.tree_toggle",
["O"] = "actions.tree_toggle_recursive",
["zA"] = "actions.tree_toggle_recursive",
["l"] = "actions.tree_open",
["zo"] = "actions.tree_open",
["L"] = "actions.tree_open_recursive",
["zO"] = "actions.tree_open_recursive",
["h"] = "actions.tree_close",
["zc"] = "actions.tree_close",
["H"] = "actions.tree_close_recursive",
["zC"] = "actions.tree_close_recursive",
["zR"] = "actions.tree_open_all",
["zM"] = "actions.tree_close_all",
["zx"] = "actions.tree_sync_folds",
["zX"] = "actions.tree_sync_folds",
},
-- When true, don't load aerial until a command or function is called
-- Defaults to true, unless `on_attach` is provided, then it defaults to false
lazy_load = true,
2021-06-18 02:06:21 +02:00
-- Disable aerial on files with this many lines
disable_max_lines = 10000,
-- Disable aerial on files this size or larger (in bytes)
disable_max_size = 2000000, -- Default 2MB
-- A list of all symbols to display. Set to false to display all symbols.
-- This can be a filetype map (see :help aerial-filetype-map)
-- To see all available values, see :help SymbolKind
filter_kind = {
"Class",
"Constructor",
"Enum",
"Function",
"Interface",
"Module",
"Method",
"Struct",
},
-- Determines line highlighting mode when multiple splits are visible.
-- split_width Each open window will have its cursor location marked in the
-- aerial buffer. Each line will only be partially highlighted
-- to indicate which window is at that location.
-- full_width Each open window will have its cursor location marked as a
-- full-width highlight in the aerial buffer.
-- last Only the most-recently focused window will have its location
-- marked in the aerial buffer.
-- none Do not show the cursor locations in the aerial window.
2021-07-06 03:06:17 +02:00
highlight_mode = "split_width",
2021-06-18 02:06:21 +02:00
-- Highlight the closest symbol if the cursor is not exactly on one.
highlight_closest = true,
-- Highlight the symbol in the source buffer when cursor is in the aerial win
highlight_on_hover = false,
-- When jumping to a symbol, highlight the line for this many ms.
-- Set to false to disable
highlight_on_jump = 300,
2021-06-18 02:06:21 +02:00
-- Define symbol icons. You can also specify "<Symbol>Collapsed" to change the
-- icon when the tree is collapsed at that symbol, or "Collapsed" to specify a
-- default collapsed icon. The default icon set is determined by the
-- "nerd_font" option below.
-- If you have lspkind-nvim installed, it will be the default icon set.
-- This can be a filetype map (see :help aerial-filetype-map)
icons = {},
2021-06-18 06:02:44 +02:00
2022-02-20 10:44:21 +01:00
-- Control which windows and buffers aerial should ignore.
-- If attach_mode is "global", focusing an ignored window/buffer will
2022-02-20 10:44:21 +01:00
-- not cause the aerial window to update.
-- If open_automatic is true, focusing an ignored window/buffer will not
-- cause an aerial window to open.
-- If open_automatic is a function, ignore rules have no effect on aerial
-- window opening behavior; it's entirely handled by the open_automatic
-- function.
ignore = {
-- Ignore unlisted buffers. See :help buflisted
unlisted_buffers = true,
-- List of filetypes to ignore.
filetypes = {},
-- Ignored buftypes.
-- Can be one of the following:
-- false or nil - No buftypes are ignored.
-- "special" - All buffers other than normal buffers are ignored.
-- table - A list of buftypes to ignore. See :help buftype for the
-- possible values.
-- function - A function that returns true if the buffer should be
-- ignored or false if it should not be ignored.
-- Takes two arguments, `bufnr` and `buftype`.
buftypes = "special",
-- Ignored wintypes.
-- Can be one of the following:
-- false or nil - No wintypes are ignored.
-- "special" - All windows other than normal windows are ignored.
-- table - A list of wintypes to ignore. See :help win_gettype() for the
-- possible values.
-- function - A function that returns true if the window should be
-- ignored or false if it should not be ignored.
-- Takes two arguments, `winid` and `wintype`.
wintypes = "special",
},
-- When you fold code with za, zo, or zc, update the aerial tree as well.
-- Only works when manage_folds = true
2021-06-18 06:02:44 +02:00
link_folds_to_tree = false,
-- Fold code when you open/collapse symbols in the tree.
-- Only works when manage_folds = true
link_tree_to_folds = true,
2021-06-18 06:02:44 +02:00
-- Use symbol tree for folding. Set to true or false to enable/disable
-- 'auto' will manage folds if your previous foldmethod was 'manual'
manage_folds = false,
2021-06-18 06:02:44 +02:00
-- Set default symbol icons to use patched font icons (see https://www.nerdfonts.com/)
-- "auto" will set it to true if nvim-web-devicons or lspkind-nvim is installed.
2021-07-06 03:06:17 +02:00
nerd_font = "auto",
2021-06-18 02:06:21 +02:00
2022-01-02 01:05:51 +01:00
-- Call this function when aerial attaches to a buffer.
2022-10-21 21:26:47 +02:00
on_attach = function(bufnr) end,
2022-01-02 01:05:51 +01:00
-- Call this function when aerial first sets symbols on a buffer.
2022-10-21 21:26:47 +02:00
on_first_symbols = function(bufnr) end,
-- Automatically open aerial when entering supported buffers.
-- This can be a function (see :help aerial-open-automatic)
open_automatic = false,
2021-06-18 02:06:21 +02:00
2021-06-18 06:02:44 +02:00
-- Run this command after jumping to a symbol (false will disable)
2021-07-06 03:06:17 +02:00
post_jump_cmd = "normal! zz",
2021-06-18 02:06:21 +02:00
-- When true, aerial will automatically close after jumping to a symbol
close_on_select = false,
-- The autocmds that trigger symbols update (not used for LSP backend)
update_events = "TextChanged,InsertLeave",
-- Show box drawing characters for the tree hierarchy
show_guides = false,
-- Customize the characters used when show_guides = true
guides = {
-- When the child item has a sibling below it
mid_item = "├─",
-- When the child item is the last in the list
last_item = "└─",
-- When there are nested child guides to the right
nested_top = "│ ",
-- Raw indentation
whitespace = " ",
},
-- Options for opening aerial in a floating win
float = {
-- Controls border appearance. Passed to nvim_open_win
border = "rounded",
-- Determines location of floating window
-- cursor - Opens float on top of the cursor
-- editor - Opens float centered in the editor
-- win - Opens float centered in the window
relative = "cursor",
-- These control the height of the floating window.
-- They can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
-- min_height and max_height can be a list of mixed types.
-- min_height = {8, 0.1} means "the greater of 8 rows or 10% of total"
max_height = 0.9,
height = nil,
min_height = { 8, 0.1 },
override = function(conf, source_winid)
-- This is the config that will be passed to nvim_open_win.
-- Change values here to customize the layout
return conf
end,
},
lsp = {
-- Fetch document symbols when LSP diagnostics update.
-- If false, will update on buffer changes.
diagnostics_trigger_update = true,
-- Set to false to not update the symbols when there are LSP errors
update_when_errors = true,
-- How long to wait (in ms) after a buffer change before updating
-- Only used when diagnostics_trigger_update = false
update_delay = 300,
},
treesitter = {
-- How long to wait (in ms) after a buffer change before updating
update_delay = 300,
},
markdown = {
-- How long to wait (in ms) after a buffer change before updating
update_delay = 300,
},
man = {
-- How long to wait (in ms) after a buffer change before updating
update_delay = 300,
},
})
```
All possible SymbolKind values can be found [in the LSP
spec](https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#symbolKind).
These are the values used for configuring icons, highlight groups, and
filtering.
2021-12-03 23:43:16 +01:00
## Third-party integrations
2021-07-15 21:44:17 +02:00
2021-07-17 00:49:10 +02:00
### Telescope
If you have [telescope](https://github.com/nvim-telescope/telescope.nvim)
installed, there is an extension for fuzzy finding and jumping to symbols. It
functions similarly to the builtin `lsp_document_symbols` picker, the main
difference being that it uses the aerial backend for the source (e.g. LSP,
treesitter, etc) and that it filters out some symbols (see the `filter_kind`
option).
You can activate the picker with `:Telescope aerial`
If you want the command to autocomplete, you can load the extension first:
2021-07-15 21:44:17 +02:00
```lua
require('telescope').load_extension('aerial')
```
The extension can be customized with the following options:
```lua
require('telescope').setup({
extensions = {
aerial = {
-- Display symbols as <root>.<parent>.<symbol>
show_nesting = {
['_'] = false, -- This key will be the default
json = true, -- You can set the option for specific filetypes
yaml = true,
}
}
}
})
```
2021-07-17 00:49:10 +02:00
### fzf
If you have [fzf](https://github.com/junegunn/fzf.vim) installed you can trigger
fuzzy finding with `:call aerial#fzf()`. To create a mapping:
2022-01-02 01:05:51 +01:00
2021-07-17 00:49:10 +02:00
```vim
nmap <silent> <leader>ds <cmd>call aerial#fzf()<cr>
```
2021-12-03 23:43:16 +01:00
### Lualine
There is a lualine component to display the symbols for your current cursor
position
```lua
require("lualine").setup({
sections = {
lualine_x = { "aerial" },
-- Or you can customize it
lualine_y = { "aerial",
-- The separator to be used to separate symbols in status line.
sep = ' ) ',
-- The number of symbols to render top-down. In order to render only 'N' last
-- symbols, negative numbers may be supplied. For instance, 'depth = -1' can
-- be used in order to render only current symbol.
depth = nil,
-- When 'dense' mode is on, icons are not rendered near their symbols. Only
-- a single icon that represents the kind of current symbol is rendered at
-- the beginning of status line.
dense = false,
-- The separator to be used to separate symbols in dense mode.
dense_sep = '.',
2022-10-01 20:07:20 +02:00
-- Color the symbol icons.
colored = true,
2021-12-03 23:43:16 +01:00
},
},
})
```
## Highlight
There are highlight groups created for each `SymbolKind`. There will be one for
the name of the symbol (`Aerial<SymbolKind>`, and one for the icon
(`Aerial<SymbolKind>Icon`). For example:
```vim
hi link AerialClass Type
hi link AerialClassIcon Special
hi link AerialFunction Special
hi AerialFunctionIcon guifg=#cb4b16 guibg=NONE guisp=NONE gui=NONE cterm=NONE
" There's also this group for the cursor position
hi link AerialLine QuickFixLine
" If highlight_mode="split_width", you can set a separate color for the
" non-current location highlight
hi AerialLineNC guibg=Gray
" You can customize the guides (if show_guide=true)
hi link AerialGuide Comment
" You can set a different guide color for each level
hi AerialGuide1 guifg=Red
hi AerialGuide2 guifg=Blue
```
2022-10-21 21:26:47 +02:00
## API
<!-- API -->
2022-10-22 05:27:34 +02:00
- [setup(opts)](doc/api.md#setupopts)
- [is_open(opts)](doc/api.md#is_openopts)
- [close()](doc/api.md#close)
- [close_all()](doc/api.md#close_all)
- [close_all_but_current()](doc/api.md#close_all_but_current)
- [open(opts)](doc/api.md#openopts)
- [open_all()](doc/api.md#open_all)
- [focus()](doc/api.md#focus)
- [toggle(opts)](doc/api.md#toggleopts)
- [select(opts)](doc/api.md#selectopts)
- [next(step)](doc/api.md#nextstep)
- [prev(step)](doc/api.md#prevstep)
- [next_up(count)](doc/api.md#next_upcount)
- [prev_up(count)](doc/api.md#prev_upcount)
- [get_location(exact)](doc/api.md#get_locationexact)
- [tree_close_all(bufnr)](doc/api.md#tree_close_allbufnr)
- [tree_open_all(bufnr)](doc/api.md#tree_open_allbufnr)
- [tree_set_collapse_level(bufnr, level)](doc/api.md#tree_set_collapse_levelbufnr-level)
- [tree_open(opts)](doc/api.md#tree_openopts)
- [tree_close(opts)](doc/api.md#tree_closeopts)
- [tree_toggle(opts)](doc/api.md#tree_toggleopts)
- [sync_folds(bufnr)](doc/api.md#sync_foldsbufnr)
- [info()](doc/api.md#info)
- [num_symbols(bufnr)](doc/api.md#num_symbolsbufnr)
- [was_closed(default)](doc/api.md#was_closeddefault)
2022-10-21 21:26:47 +02:00
<!-- /API -->
## FAQ
**Q: I accidentally opened a file into the aerial window and it looks bad. How can I prevent this from happening?**
Try installing [stickybuf](https://github.com/stevearc/stickybuf.nvim). It was designed to prevent exactly this problem.