Skip to content

cfung89/embrace.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

embrace.nvim

embrace.nvim:

Embrace your text.

embrace.nvim allows for quick addition of surrounding characters such as quotes, brackets, tags, or any string around selected text.

Features

  • Surround visual mode selection.
  • Surround visual block selection.
  • Support for:
    • For brackets: (), [], {}, <>.
    • Any single character.
    • Any string.
    • Closing HTML tags.

Installation

{
  "cfung89/embrace.nvim",
  config = function()
    require("embrace").setup()  -- For default options
  end
}

Configuration

require("embrace").setup({
  --- default configuration
  keymaps = {
    surround = "S",             -- Surround
    surround_block = "B",        -- Surround in block mode after the above keymap
    str = "S",                  -- Input string when surrounding
    block = "<leader>SB",       -- Surround in block mode directly
  }
  
  -- Custom added/modified surround input map.
  -- Must be of the form { { "<input_key>", "<opening_string>", "<closing_string" }, ... },
  -- where when input_key is entered (for example with 'S<input_key>'), the selected text will
  -- be surround with opening_string and closing string.
  -- input_key is a single char; opening and closing strings can be of any length.
  -- Example: surround_map = { { "A", "foo", "bar" } }
  -- Typing 'SA' surround the selection as follows "foo{selection}bar".
  surround_map = {},

  -- Custom added/modified surround block input map.
  -- If nil, surround_block_map is set to surround_map.
  -- Behaves the same as surround_map.
  surround_block_map = nil,
})

Usage

The following default keybindings are provided.

Visual mode

S(          Surround selected text with `( ` and ` )`
S)          Surround selected text with `(` and `)`
S[          Surround selected text with `[ ` and ` ]`
S]          Surround selected text with `[` and `]`
S{          Surround selected text with `{ ` and ` }`
S}          Surround selected text with `{` and `}`
S<          Surround selected text with `< ` and ` >`
S>          Surround selected text with `<` and `>`

S<char>     Surround selected text with provided input character.
SS          Surround selected text with provided input string.

Visual block mode

Note: These keybindings also work in "normal" visual mode. They will surround each line within the visual selection with the specified characters.

This is generally called using the surround keymap followed by surround_block

SB(         Surround selected text block with `( ` and ` )`
SB)         Surround selected text block with `(` and `)`
SB[         Surround selected text block with `[ ` and ` ]`
SB]         Surround selected text block with `[` and `]`
SB{         Surround selected text block with `{ ` and ` }`
SB}         Surround selected text block with `{` and `}`
SB<         Surround selected text block with `< ` and ` >`
SB>         Surround selected text block with `<` and `>`

SB<char>    Surround selected text block with provided input character.
SBS         Surround selected text block with provided input string.

This can also be called directly as follows, using the block keymap (without the surround keymap).

TODO

  • Fix surround visual block on lines with different tabbing.
  • Add custom surrounds.

Inspirations

About

Neovim text surround plugin

Resources

License

Stars

Watchers

Forks

Languages