ur4ltz / surround.nvim

A surround text object plugin for neovim written in lua. (Fork from blackCauldron7/surround.nvim)
MIT License
94 stars 16 forks source link

How to change default mappings? #6

Open NEX-S opened 2 years ago

NEX-S commented 2 years ago

i just want to use my own keymap...

Kurama622 commented 2 years ago

Default mappings ( https://github.com/ur4ltz/surround.nvim/blob/master/lua/surround/init.lua ):

    if vim.g.surround_mappings_style == "sandwich" then
        map("n", vim.g.surround_prefix .. vim.g.surround_prefix, "<Plug>SurroundRepeat")
        map("x", vim.g.surround_prefix,         "<Plug>SurroundAddVisual")
        map("n", vim.g.surround_prefix .. "a",  "<Plug>SurroundAddNormal")
        map("n", vim.g.surround_prefix .. "d",  "<Plug>SurroundDelete")
        map("n", vim.g.surround_prefix .. "r",  "<Plug>SurroundReplace")
        map("n", vim.g.surround_prefix .. "tq", "<Plug>SurroundToggleQuotes")
        map("n", vim.g.surround_prefix .. "tb", "<Plug>SurroundToggleBrackets")
        map("n", vim.g.surround_prefix .. "tB", "<Plug>SurroundToggleBrackets")
    elseif vim.g.surround_mappings_style == "surround" then
        map("x", "s",  "<Plug>SurroundAddVisual")
        map("n", "ys", "<Plug>SurroundAddNormal")
        map("n", "ds", "<Plug>SurroundDelete")
        map("n", "cs", "<Plug>SurroundReplace")
        map("n", "cq", "<Plug>SurroundToggleQuotes")
    end

You can refer to the following code to modify mappings:

local keymap = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
require"surround".setup{
    mappings_style = "surround",
    keymap("x", "S", "<Plug>SurroundAddVisual", opts)
}
voyeg3r commented 2 years ago

And how can I do, if by any chance I would like to map <C-1> to add single quotes at once?