Code Monkey home page Code Monkey logo

autoclose.nvim's Introduction

autoclose.nvim

Stargazers Issues Contributors

๐Ÿ“ƒ 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

Auto-delete

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

Auto-escape

Auto-indent

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

โšก 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:

  • close: If set to true, pressing the character will insert both the opening and closing characters, and place the cursor in between them.
  • escape: If set to true, pressing the character again will escape it instead of inserting a closing character.
  • pair: The table that represents the pair of opening and closing characters. This should be a two-item (list-like) table, with the opening character first and the closing character second.
  • disabled_filetypes: Table of filetypes where the specific key should not be autoclosed.
  • enabled_filetypes: Only autoclose the key under these filetypes. This option takes precedence over disabled_filetypes.
  • disable_command_mode: If set to true, the character will be disabled in command-line mode.

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:

  • disabled_filetypes: The plugin will be disabled under the filetypes in this table.
    • type of the value: table of strings
    • default value: { "text" }

Example: Disable the plugin in text and markdown file.

require("autoclose").setup({
   options = {
      disabled_filetypes = { "text", "markdown" },
   },
})
  • disable_when_touch: Set this to true will disable the auto-close function when the cursor touches character that matches touch_regex.

    • type of the value: boolean
    • default value: false
  • touch_regex

    • type of the value: string
    • default value: "[%w(%[{]" (alphanumeric characters or ( or [ or {)

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.

  • pair_spaces: Pair the spaces when cursor is inside a pair of keys.
    • type of the value: boolean
    • default value: false

Example:

The | is your cursor in insert mode.

import {|}

after inserting a space:

import { | }
  • auto_indent: Enable auto-indent feature

    • type of the value: boolean
    • default value: true
  • disable_command_mode: Disable autoclose for command mode globally

    • type of the value: boolean
    • default value: false

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.

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.