Home

Awesome

nvim-yati

Yet another tree-sitter indent plugin for Neovim.

This plugin was originally created when the experience of builtin indent module of nvim-treesitter was still terrible. Now since it has improved a lot with better community support, this plugin should be no longer needed if the upstream one already satisfies you.

If you are still frustrated with the 'official' indent module or interested in this plugin, welcome to provide feedback or submit any issues. Take a glance at features to learn about the differences.

<details> <summary> <b>Supported languages</b> </summary> </details>

More languages could be supported by setup or adding config files to configs/ directory.

Compatibility

This plugin is always developed based on latest neovim and nvim-treesitter. Please consider upgrading them if there is any compatibility issue.

The plugin has been completely rewritten since legacy tag. Use that if you prefer not migrating to the current version for some reason.

Installation

packer.nvim:

use({ "yioneko/nvim-yati", tag = "*", requires = "nvim-treesitter/nvim-treesitter" })

vim-plug:

Plug "nvim-treesitter/nvim-treesitter"
Plug "yioneko/nvim-yati", { 'tag': '*' }

Setup

The module is required to be enabled to work:

require("nvim-treesitter.configs").setup {
  yati = {
    enable = true,
    -- Disable by languages, see `Supported languages`
    disable = { "python" },

    -- Whether to enable lazy mode (recommend to enable this if bad indent happens frequently)
    default_lazy = true,

    -- Determine the fallback method used when we cannot calculate indent by tree-sitter
    --   "auto": fallback to vim auto indent
    --   "asis": use current indent as-is
    --   "cindent": see `:h cindent()`
    -- Or a custom function return the final indent result.
    default_fallback = "auto"
  },
  indent = {
    enable = false -- disable builtin indent module
  }
}

I also created an accompanying regex-based indent plugin (vim-tmindent) to support saner fallback indent calculation, which could be a drop-in replacement of builtin indent method of vim. See integration for its fallback setup.

If you want to use the indent module simultaneously, disable the indent module for languages to be handled by this plugin.

require("nvim-treesitter.configs").setup {
  indent = {
    enable = true,
    disable = { "html", "javascript" }
  },
  -- And optionally, disable the conflict warning emitted by plugin
  yati = {
    suppress_conflict_warning = true,
  },
}

Example for a more customized setup:

local get_builtin = require("nvim-yati.config").get_builtin
-- This is just an example, not recommend to do this since the result is unpredictable
local js_overrides = vim.tbl_deep_extend("force", get_builtin("javascript"), {
  lazy = false,
  fallback = function() return -1 end,
  nodes = {
    ["if_statement"] = { "scope" }, -- set attributes by node
  },
  handlers = {
    on_initial = {},
    on_travers = {
      function(ctx) return false end, -- set custom handlers
    }
  }
})

require("nvim-treesitter.configs").setup {
  yati = {
    enable = true,
    disable = { "python" },
    default_lazy = false,
    default_fallback = function() return -1 end, -- provide custom fallback indent method
    overrides = {
      javascript = js_overrides -- override config by language
    }
  }
}

More technical details goes there (highly unstable): CONFIG.md.

Features

Notes

Credits