mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 11:06:54 -04:00
Instead, call `require('nvim-treesitter').install( { ... } )` manually.
This gives users full control over how they want to install parsers
(sync, from grammar, limited concurrency) and obviates the need for
calling `setup` for most users.
191 lines
5.7 KiB
Text
191 lines
5.7 KiB
Text
*nvim-treesitter.txt* Treesitter parser and query installer for Neovim
|
|
|
|
Authors:
|
|
Kiyan Yazdani <yazdani.kiyan@protonmail.com>
|
|
Thomas Vigouroux <tomvig38@gmail.com>
|
|
Stephan Seitz <stephan.seitz@fau.de>
|
|
Steven Sojka <Steven.Sojka@tdameritrade.com>
|
|
Santos Gallegos <stsewd@protonmail.com>
|
|
https://github.com/nvim-treesitter/nvim-treesitter/graphs/contributors
|
|
|
|
Type |gO| to see the table of contents.
|
|
|
|
==============================================================================
|
|
INTRODUCTION *nvim-treesitter-intro*
|
|
|
|
Nvim-treesitter provides functionalities for managing treesitter parsers and
|
|
compatible queries for core features (highlighting, injections, fold, indent).
|
|
|
|
WARNING: This is work in progress and requires the latest commit on Neovim
|
|
`master`.
|
|
|
|
==============================================================================
|
|
QUICK START *nvim-treesitter-quickstart*
|
|
|
|
To configure `nvim-treesitter`, put this in your `init.lua` file:
|
|
>lua
|
|
require'nvim-treesitter'.setup {
|
|
-- A directory to install the parsers and queries to.
|
|
-- Defaults to the `stdpath('data')/site` dir.
|
|
install_dir = "/some/path/to/store/parsers",
|
|
-- List of parsers to ignore installing (for "stable" etc.)
|
|
ignore_install = { "some_parser" },
|
|
}
|
|
|
|
NOTE: You do not need to call `setup` to use this plugin with the default
|
|
settings!
|
|
|
|
Parsers and queries can then be installed with >lua
|
|
require'nvim-treesitter'.install { 'rust', 'javascript', 'zig' }
|
|
<
|
|
(This is a no-op if the parsers are already installed.)
|
|
|
|
To check installed parsers and queries, use `:checkhealth nvim-treesitter`.
|
|
|
|
==============================================================================
|
|
COMMANDS *nvim-treesitter-commands*
|
|
|
|
*:TSInstall*
|
|
:TSInstall {language} ... ~
|
|
|
|
Install one or more treesitter parsers.
|
|
You can use |:TSInstall| `all` to install all parsers. Use |:TSInstall!| to
|
|
force the reinstallation of already installed parsers.
|
|
|
|
*:TSUpdate*
|
|
:TSUpdate {language} ... ~
|
|
|
|
Update the installed parser for one more {language} or all installed parsers
|
|
if {language} is omitted. The specified parser is installed if it is not already
|
|
installed.
|
|
|
|
*:TSUninstall*
|
|
:TSUninstall {language} ... ~
|
|
|
|
Deletes the parser for one or more {language}. You can use 'all' for language
|
|
to uninstall all parsers.
|
|
|
|
==============================================================================
|
|
INDENTATION *nvim-treesitter-indentation*
|
|
|
|
Indentation based on treesitter for the |=| operator.
|
|
NOTE: this is an experimental feature and will be upstreamed to Neovim when
|
|
stable.
|
|
|
|
To enable it for a supported parser, add the following to a corresponding
|
|
`FileType` autocommand or `ftplugin/<lang>.lua`: >lua
|
|
|
|
vim.bo.indentexpr = 'v.lua:require'nvim-treesitter'.indentexpr()'
|
|
|
|
<
|
|
|
|
Indentation for a language is controlled by `indents.scm` queries. The
|
|
following captures are supported:
|
|
|
|
|
|
`@indent` *nvim-treesitter-indentation-queries*
|
|
Queries can use the following captures: `@indent.begin` and `@indent.dedent`,
|
|
`@indent.branch`, `@indent.end` or `@indent.align`. An `@indent.ignore` capture tells
|
|
treesitter to ignore indentation and a `@indent.zero` capture sets
|
|
the indentation to 0.
|
|
|
|
`@indent.begin` *nvim-treesitter-indentation-indent.begin*
|
|
The `@indent.begin` specifies that the next line should be indented. Multiple
|
|
indents on the same line get collapsed. Eg.
|
|
|
|
>query
|
|
(
|
|
(if_statement)
|
|
(ERROR "else") @indent.begin
|
|
)
|
|
<
|
|
Indent can also have `indent.immediate` set using a `#set!` directive, which
|
|
permits the next line to indent even when the block intended to be indented
|
|
has no content yet, improving interactive typing.
|
|
|
|
eg for python:
|
|
>query
|
|
((if_statement) @indent.begin
|
|
(#set! indent.immediate 1))
|
|
<
|
|
|
|
Will allow:
|
|
>python
|
|
if True:<CR>
|
|
# Auto indent to here
|
|
|
|
`@indent.end` *nvim-treesitter-indentation-indent.end*
|
|
An `@indent.end` capture is used to specify that the indented region ends and
|
|
any text subsequent to the capture should be dedented.
|
|
|
|
`@indent.branch` *nvim-treesitter-indentation-indent.branch*
|
|
An `@indent.branch` capture is used to specify that a dedented region starts
|
|
at the line including the captured nodes.
|
|
|
|
`@indent.dedent` *nvim-treesitter-indentation-indent.dedent*
|
|
A `@indent.dedent` capture specifies dedenting starting on the next line.
|
|
>
|
|
`@indent.align` *nvim-treesitter-indentation-aligned_indent.align*
|
|
Aligned indent blocks may be specified with the `@indent.align` capture.
|
|
This permits
|
|
|
|
>
|
|
foo(a,
|
|
b,
|
|
c)
|
|
<
|
|
As well as
|
|
>
|
|
foo(
|
|
a,
|
|
b,
|
|
c)
|
|
<
|
|
and finally
|
|
>
|
|
foo(
|
|
a,
|
|
b,
|
|
c
|
|
)
|
|
<
|
|
To specify the delimiters to use `indent.open_delimiter` and
|
|
`indent.close_delimiter` should be used. Eg.
|
|
>query
|
|
((argument_list) @indent.align
|
|
(#set! indent.open_delimiter "(")
|
|
(#set! indent.close_delimiter ")"))
|
|
<
|
|
|
|
For some languages the last line of an `indent.align` block must not be
|
|
the same indent as the natural next line.
|
|
|
|
For example in python:
|
|
|
|
>python
|
|
if (a > b and
|
|
c < d):
|
|
pass
|
|
|
|
Is not correct, whereas
|
|
>python
|
|
if (a > b and
|
|
c < d):
|
|
pass
|
|
|
|
Would be correctly indented. This behavior may be chosen using
|
|
`indent.avoid_last_matching_next`. Eg.
|
|
|
|
>query
|
|
(if_statement
|
|
condition: (parenthesized_expression) @indent.align
|
|
(#set! indent.open_delimiter "(")
|
|
(#set! indent.close_delimiter ")")
|
|
(#set! indent.avoid_last_matching_next 1)
|
|
)
|
|
<
|
|
Could be used to specify that the last line of an `@indent.align` capture
|
|
should be additionally indented to avoid clashing with the indent of the first
|
|
line of the block inside an if.
|
|
|
|
vim:tw=78:ts=8:expandtab:noet:ft=help:norl:
|