GithubHelp home page GithubHelp logo

neovim / playground Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nvim-treesitter/playground

0.0 2.0 0.0 2.79 MB

Treesitter playground integrated into Neovim

License: Apache License 2.0

Scheme 0.55% Lua 98.43% Vim Script 1.02%

playground's Introduction

Neovim Treesitter Playground

View treesitter information directly in Neovim!

nvim-treesitter-playground

Requirements

Setup

Install the plugin (vim-plug shown):

Plug 'nvim-treesitter/nvim-treesitter'
Plug 'nvim-treesitter/playground'

It's also recommended that you install the query parser for query editor highlighting. Run this after installing the above plugins.

:TSInstall query

The configuration is like any other nvim-treesitter module.

require "nvim-treesitter.configs".setup {
  playground = {
    enable = true,
    disable = {},
    updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
    persist_queries = false, -- Whether the query persists across vim sessions
    keybindings = {
      toggle_query_editor = 'o',
      toggle_hl_groups = 'i',
      toggle_injected_languages = 't',
      toggle_anonymous_nodes = 'a',
      toggle_language_display = 'I',
      focus_language = 'f',
      unfocus_language = 'F',
      update = 'R',
      goto_node = '<cr>',
      show_help = '?',
    },
  }
}

Usage

The tree can be toggled using the command :TSPlaygroundToggle.

Keybindings

  • R: Refreshes the playground view when focused or reloads the query when the query editor is focused.
  • o: Toggles the query editor when the playground is focused.
  • a: Toggles visibility of anonymous nodes.
  • i: Toggles visibility of highlight groups.
  • I: Toggles visibility of the language the node belongs to.
  • t: Toggles visibility of injected languages.
  • f: Focuses the language tree under the cursor in the playground. The query editor will now be using the focused language.
  • F: Unfocuses the currently focused language.
  • <cr>: Go to current node in code buffer

Query Editor

Press o to show the query editor. Write your query like (node) @capture, put the cursor under the capture to highlight the matches.

Completions

When you are on a query buffer, you can get a list of suggestions with Ctrl-X Ctrl-O. See :h 'omnifunc'.

Query Linter

The playground can lint query files for you. For that, you need to activate the query_linter module:

require "nvim-treesitter.configs".setup {
  query_linter = {
    enable = true,
    use_virtual_text = true,
    lint_events = {"BufWrite", "CursorHold"},
  },
}

image

Show treesitter and syntax highlight groups under the cursor

The playground comes with :TSHighlightCapturesUnderCursor that shows any treesitter or syntax highlight groups under the cursor.

image

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.