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.0

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 an 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 release, I plan to provide documentation that will include how to add support for other languages.

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

Install Vpe_Syntax

I have only used this on Linux (Windows testing hopefully coming soon) so this is all Linux specific.

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.

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.0.tar.gz (35.2 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.0-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vpe_syntax-0.1.0.tar.gz
  • Upload date:
  • Size: 35.2 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.0.tar.gz
Algorithm Hash digest
SHA256 ec681fb5641b929a632df0738329b6f485eaeb41bcaf1c6b294b95f902a2e94d
MD5 1da773eec9c5fb06f1ddfbe10150e62c
BLAKE2b-256 e2379917221aace3df5b49a6da782c1b0153cf8cc7cd0f8d9bf533325017c73e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: vpe_syntax-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b951fefd1b3b85bd6bd9374c0d261940548c1d20a325954a13c18b863cfd7255
MD5 1817f22f2770dd5354634c28e304a127
BLAKE2b-256 6540f7b0aaf62fa3d3b3e9fb96fa16b9b4d64145bd9a32a758a04ac12de138b2

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