Giter Site home page Giter Site logo

umgbhalla / surround.nvim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ur4ltz/surround.nvim

0.0 1.0 0.0 83 KB

A surround text object plugin for neovim written in lua. (Fork from blackCauldron7/surround.nvim)

License: MIT License

Lua 100.00%

surround.nvim's Introduction

surround.nvim

Features

Key mappings

There are two keymap modes for normal mode mappings.

  • sandwich and surround and they can be set using the options mentioned below.

Normal Mode - Sandwich Mode

  1. Provides key mapping to add surrounding characters.( visually select then press s<char> or press sa{motion}{char})
  2. Provides key mapping to replace surrounding characters.( sr<from><to> )
  3. Provides key mapping to delete surrounding characters.( sd<char> )
  4. ss repeats last surround command.

Normal Mode - Surround Mode

  1. Provides key mapping to add surrounding characters.( visually select then press s<char> or press ys{motion}{char})
  2. Provides key mapping to replace surrounding characters.( cs<from><to> )
  3. Provides key mapping to delete surrounding characters.( ds<char> )

Insert Mode

  • <c-s><char> will insert both pairs in insert mode.
  • <c-s><char><space> will insert both pairs in insert mode with surrounding whitespace.
  • <c-s><char><c-s> will insert both pairs on newlines insert mode.

IDK I was bored

  1. Cycle surrounding quotes type. (stq)
  2. Cycle surrounding brackets type. (stb)
  3. Use <char> == f for adding, replacing, deleting functions.

Installation

  1. vim-plug: Plug 'blackcauldron7/surround.nvim' and Put this somewhere in your init.vim: lua require"surround".setup{}
  2. minPlug: MinPlug blackcauldron7/surround.nvim and Put this somewhere in your init.vim: lua require"surround".setup{}
  3. Packer.nvim
use {
  "blackCauldron7/surround.nvim",
  config = function()
    require"surround".setup {mappings_style = "sandwich"}
  end
}

OR

use {
  "blackCauldron7/surround.nvim",
  config = function()
    require"surround".setup {mappings_style = "surround"}
  end
}

Configuration

Format: for vimscript let g:surround_<option> and for lua vim.g.surround_<option>

  • prefix: prefix for sandwich mode. (default: s)
  • pairs: dictionary or lua table of form { nestable: {{},...}, linear: {{},....} } where linear is an array of arrays which contain non-nestable pairs of surrounding characters first opening and second closing like ", ' and nestable is an array of arrays which contain nestable pairs of surrounding characters like (, {, [. The key to each pair can be used as an alias instead of either value. For single-character pairs, this alias is optional and you can just use either value. For pairs that use multiple characters per bracket, an alias is required. You can for example set pairs = { linear = { Q = {'"""','"""'} } } to use Q to add triple double quotes around selected text. The key "f" is used to add/replace functions, configuring it for a pair will override that functionality.
    • Aliases must be a single letter.
    • Aliases are case-sensitive.
    • Aliases must be unique across the entire pairs table.
    • When adding your own pairs, you do not need to specify the defaults. Your own values will be added to the default table and overwrite aliases when necessary.
    • Defaults:
{
  nestable = {
    b = { "(", ")" },
    s = { "[", "]" },
    B = { "{", "}" },
    a = { "<", ">" }
    },
  linear = {
    q = { "'", "'" },
    t = { "`", "`" },
    d = { '"', '"' }
  },
}
  • context_offset: number of lines to look for above and below the current line while searching for nestable pairs. (default: 100)
  • prompt: whether to print a prompt in the command window asking for input. (default: true)
  • load_autogroups: whether to load inbuilt autogroups or not. (default: false)
  • mappings_style: "surround" or "sandwich" (default: sandwich)
  • load_keymaps: whether to load inbuilt keymaps or not. (default: true)
  • quotes: an array of items to be considered as quotes while cycling through them. (default: ["'", '"'])
  • brackets: an array of items to be considered as brackets while cycling through them. (default: ["(", "{", "["])
  • map_insert_mode: whether to load insert mode mappings or not. (default: true)
  • space_on_closing_char: if the closing char should add surround space rather than the opening char. (default: false)
  • space_on_alias: if the alias should add surround space. (default: false)

or pass a lua table to the setup function

require"surround".setup {
  context_offset = 100,
  load_autogroups = false,
  mappings_style = "sandwich",
  map_insert_mode = true,
  quotes = {"'", '"'},
  brackets = {"(", '{', '['},
  space_on_closing_char = false,
  pairs = {
    nestable = { b = { "(", ")" }, s = { "[", "]" }, B = { "{", "}" }, a = { "<", ">" } },
    linear = { q = { "'", "'" }, t = { "`", "`" }, d = { '"', '"' }
  },
  prefix = "s"
}

Caveats

  1. Only supports neovim and always will because it's written in lua which is neovim exclusive.
  2. Doesn't support python docstrings and html tags yet. Either can be added to the pairs table with an alias as shortcut. (No dynamic tags yet, though. You need to add the tags you want beforehand.)
  3. No vim docs(idk how to make them. Need help)
  4. Support for repeating actions with . requires tpope's vim-repeat.

Contributing

You are more than welcome to submit PR for a feature you would like to see or bug fixes.

surround.nvim's People

Contributors

daxtorim avatar she3o avatar ur4ltz avatar joakker avatar rish987 avatar

Watchers

 avatar

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.