Home

Awesome

<!-- panvimdoc-ignore-start --> <h1 align="center"> autoclose.nvim </h1> <p align="center"> <a href="https://github.com/m4xshen/autoclose.nvim/stargazers"> <img alt="Stargazers" src="https://img.shields.io/github/stars/m4xshen/autoclose.nvim?style=for-the-badge&logo=starship&color=fae3b0&logoColor=d9e0ee&labelColor=282a36" /> </a> <a href="https://github.com/m4xshen/autoclose.nvim/issues"> <img alt="Issues" src="https://img.shields.io/github/issues/m4xshen/autoclose.nvim?style=for-the-badge&logo=gitbook&color=ddb6f2&logoColor=d9e0ee&labelColor=282a36" /> </a> <a href="https://github.com/m4xshen/autoclose.nvim/contributors"> <img alt="Contributors" src="https://img.shields.io/github/contributors/m4xshen/autoclose.nvim?style=for-the-badge&logo=opensourceinitiative&color=abe9b3&logoColor=d9e0ee&labelColor=282a36" /> </a> </p>

📃 Introduction

A minimalist Neovim plugin that auto pairs & closes brackets written in 100% Lua.

⚙️ Functions

Most functions work in both insert and command-line mode.

Auto-close

<img src="https://user-images.githubusercontent.com/74842863/208931426-4f171094-e1c8-4f85-918a-92250d92c933.gif" width="500"/>

Auto-delete

(works in <BS> and <C-W>)

<img src="https://user-images.githubusercontent.com/74842863/208931458-0ed78f76-0080-4aa9-a36e-e55881090a0c.gif" width="500"/>

Auto-escape

<img src="https://user-images.githubusercontent.com/74842863/208931512-6f06036a-267a-42d7-9d3e-58a7ddfab1a6.gif" width="500"/>

Auto-indent

(works in <CR> and <S-CR>, only in insert mode)

<img src="https://user-images.githubusercontent.com/74842863/208931561-b9170d08-0697-49b4-90fb-6d432e03c393.gif" width="500"/> <!-- panvimdoc-ignore-end -->

⚡ Requirements

📦 Installation

  1. Install via your favorite package manager.
Plug 'm4xshen/autoclose.nvim'
use 'm4xshen/autoclose.nvim'
  1. Setup the plugin in your init.lua.
require("autoclose").setup()

🔧 Configuration

You can pass your config table into the setup() function.

Keys

The available options in keys:

Example: Add a $$ pair.

require("autoclose").setup({
   keys = {
      ["$"] = { escape = true, close = true, pair = "$$", disabled_filetypes = {} },
   },
})

You can also overwrite the default config.

Example: Remove the escape function of >.

require("autoclose").setup({
   keys = {
      [">"] = { escape = false, close = false, pair = "<>", disabled_filetypes = {} },
   },
})

Options

The available options in options:

Example: Disable the plugin in text and markdown file.

require("autoclose").setup({
   options = {
      disabled_filetypes = { "text", "markdown" },
   },
})

Example:

Your current file: ( ^ points to your cursor position)

word
^

You press ( and the file will become

(word
^

It doesn't autoclose for you because your cursor touches w.

Example:

The | is your cursor in insert mode.

import {|}

after inserting a space:

import { | }

Default config

local config = {
   keys = {
      ["("] = { escape = false, close = true, pair = "()" },
      ["["] = { escape = false, close = true, pair = "[]" },
      ["{"] = { escape = false, close = true, pair = "{}" },

      [">"] = { escape = true, close = false, pair = "<>" },
      [")"] = { escape = true, close = false, pair = "()" },
      ["]"] = { escape = true, close = false, pair = "[]" },
      ["}"] = { escape = true, close = false, pair = "{}" },

      ['"'] = { escape = true, close = true, pair = '""' },
      ["'"] = { escape = true, close = true, pair = "''" },
      ["`"] = { escape = true, close = true, pair = "``" },
   },
   options = {
      disabled_filetypes = { "text" },
      disable_when_touch = false,
      touch_regex = "[%w(%[{]",
      pair_spaces = false,
      auto_indent = true,
      disable_command_mode = false,
   },
}

autoclose.nvim vs other plugins

Some plugins such as nvim-autopairs and ultimate-autopair.nvim provide a wider range of features such as fast wrap, treesitter pair checking, etc., but some users may not need all of them. If you just want the basic functionality of editing with pairs, you can use autoclose.nvim to achieve the same thing in a simpler and faster way.