Skip to main content

Tree-sitter based syntax highlighting for Vim

Project description

 _    ______  ______    _____             __
| |  / / __ \/ ____/   / ___/__  ______  / /_____ __  __
| | / / /_/ / __/      \__ \/ / / / __ \/ __/ __ `/ |/_/  Syntax highlighing
| |/ / ____/ /___     ___/ / /_/ / / / / /_/ /_/ />  <    using Tree-sitter
|___/_/   /_____/____/____/\__, /_/ /_/\__/\__,_/_/|_|
                            /____/

Welcome to the Tree-sitter support for Vim.

status:

This is version 0.1.2

This is alpha software, but I use it all the time and it has been behaving reliably for me (but see the issues and limitations listed below).

This library is targeted at ‘vanilla’ Vim. It is doubtful that this could easily be made to work with Neovim and, in any case, Neovim already has quite mature support for Tree-sitter.

Currently the only supported languages are Python and C. It should be not difficult to add many of the languages that are available on PyPi. They typically have names like tree=sitter-bash, tree-sitter-pascal, etc. In the next point release (0.2), I plan to provide documentation that will include how to add support for other languages.

News

Version 0.1.1 enables support for Windows.

Requirements

You will need Vim 9.0 or greater and obviously it will have to have been built with Python 3 support, at least version 3.11.

Issues and limitations

There are some notable issues.

  1. No support for selective spell checking.

    Vim’s regular expression based syntax highlighting provides a mechanism to mark only some parts of a buffer (e.g. comments) to be spell checked. VPE_Syntax uses text properties to provide highlighting. Text properties do not currently provide support for this. I hope to supply a pull request to get this added to Vim.

    If possible, release 0.2 will contain a work around.

  2. Synchronisation issues.

    VPE_Syntax (well strictly speaking VPE_Sitter) depends on Vim’s listener_add() functionality to track when a buffer’s contents change and thus trigger Tree-sitter incremental re-parse operations. Under some circumstances, the listener_add provided callbacks can occur in away that does not properly match the buffer’s contents. This results incorrect syntax highlighting.

    This occurs relatively rarely. When it does, you can save your file and then reload (using :e!) to force a full re-parse.

    I plan to supply a pull request to allow VPE_Syntax to get the change notifications that it needs for reliable operation.

    If possible, release 0.2 will contain a work around.

  3. Embedded language support is largely missing.

    There is some experimental code, but I am not really using it and it may not even work at the moment.

Installation

I have only used this on Linux and Windows.

Linux

As advised for VPE, it is recommended that you use a virtual environment, hosted within your Vim configuration tree. You may find it useful to read the VPE Linux installation instructions for some background. The following assumes that your Vim configuration directory is $HOME/.vim.

  1. If you do not already have a virtual environment then create one:

    # Make sure you are in your $HOME directory
    python -m venv .vim/lib/python
  2. Activate the virtual environment and install vpe_syntax.

    # Activate the virtual environment.
    source .vim/lib/python/bin/activate
    
    # Install VPE.
    python -m pip install vpe_syntax
  3. If you did not already have VPE installed then you will need to perform additional one-off installation of support Vim plugin code. Follow the VPE first installations, steps 2 to 4.

Windows

A user install is recommended.

  1. Install using the command.

    # Install VPE.
    python -m pip install --user vpe_syntax
  2. If you did not already have VPE installed then you will need to perform additional one-off installation of support Vim plugin code. Follow the VPE first installations, steps 2 to 4.

Install Tree-sitter parsers

The above steps should install all the direct dependencies of VPE_Syntax, but you will need to separately install parsers for the languages you wish to highlight. Assuming you want to use both supported languages then before you exit the virtual environment do:

python3 -m pip install tree-sitter-python==0.23.6 tree-sitter-c==0.21.4

The Tree-sitter API seems to be somewhat fast moving, so I recommend using the exact versions given above.

You can then deactivate the virtual environment.

deactivate

Using Vpe_Syntax

One everything is correctly installed, you should find that your Vim has gained a Synsit command. The important form of this is:

Synsit on

Which will enable Tree-sitter based highlighting in the current buffer, provided it contains C or Python code. If everything is working you will likely see some differences in the way your code is coloured, but by an large things will be quite similar.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vpe_syntax-0.1.2.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vpe_syntax-0.1.2-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file vpe_syntax-0.1.2.tar.gz.

File metadata

  • Download URL: vpe_syntax-0.1.2.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for vpe_syntax-0.1.2.tar.gz
Algorithm Hash digest
SHA256 be0624e42328e03d305d704d04f75963c6f075903b11233e52b7080eb4f0b1dd
MD5 b5fdac0aeb0e4d800f60bdb7a25c66e6
BLAKE2b-256 6007bb5667bdd300734bdc14dc1cca4913200e24014a597725c9a4f9c6558e73

See more details on using hashes here.

File details

Details for the file vpe_syntax-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: vpe_syntax-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for vpe_syntax-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 755fd0eebf9b54e04507402640278a62c82d5fe85455b39851ca8a5f53e5e99b
MD5 ae2af524d85d4e255663303105786050
BLAKE2b-256 a4876ad688b3b036bf8dd6012851dd965204832382a0ea1b19ede2548ca87bd5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page