Skip to content

cschierig/twins.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twins.nvim

Twins.nvim is a simple lua plugin which automatically closes braces and other pairs based on the file type. The plugin is currently in early development and isn't very smart about inserting and deleting (yet).

Features

  • Automatically closes braces and other pairs when left side is inserted.
  • Move past right side of pair when entering tab before it.
  • Language-dependent auto-closing pairs
  • Supports treesitter injected languages
  • delete left and right side when deleting pair whose characters are touching.

Not yet implemented

  • dot repeat
  • nested languages
  • Treesitter support to detect if a pair should be closed.

Installation

To install the plugin, use your favourite plugin manager to clone the repo and proceed by following the instructions in the configuration section.

Dependencies

Packer.nvim

use {
  'cschierig/twins.nvim',
  requires = { 'nvim-treesitter/nvim-treesitter' },
  event = 'BufEnter',
  config = function()
    require('twins').setup()
  end
}

Lazy.nvim

{
  'cschierig/twins.nvim',
  dependencies = { 'nvim-treesitter/nvim-treesitter' },
  event = 'BufEnter',
  config = true,
}

Configuration

Note Twins doesn't have proper error handling yet, so errors in the configuration may result in unhelpful stacktraces.

The configuration is a table which is passed as the first argument to the setup() function. It has the following structure:

{
  pairs = {
    -- name = { 'left', 'right' }
    parens = { '(', ')' },
    curly = { '{', '}' },
    square = { '[', ']' },
    dquotes = { '"' } -- optional syntax if the left and the right tokens are the same
  },
  languages = {
    -- pairs which are used for all languages
    ['*'] = {
      -- list of pairs
      'parens'
    },
    c = {
      -- additional pairs used by c
      'curly',
      'square'
    },
    c_sharp = 'c', -- define c_sharp as an alias for c, making both languages use the same pairs
    markdown = {
      { '_', '_' } -- pairs can also be specified in the language configuration
    },
  },
  keys = {
    tabout = true -- enables tabbing out of pairs
    delete_pair = true -- when deleting the left twin with backspace, the right one will be deleted as well if it is to the right of the cursor
  }
}

The default configuration can be at the beginning of this file.

Similar (better) plugins

About

Neovim plugin which automatically closes open pairs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages