Kit
Kit

Reputation: 31513

Vim Surround inserts extra space around the word

When I select the word and use the surround plugin with S:

foobar

It becomes

( foobar )

How do I remove the extra spaces, so that it becomes

(foobar)

What should I place in my settings?

Upvotes: 124

Views: 10783

Answers (3)

Joseph Chai
Joseph Chai

Reputation: 131

You can overwrite the default behavior and make ( surround without spaces, an example here in lua:

return {
  {
    "kylechui/nvim-surround",
    -- tag = "*", -- Use for stability; omit to use `main` branch for the latest features
    config = function()
      require("nvim-surround").setup {
        surrounds = {
          ["("] = {
            add = function() return { { "(" }, { ")" } } end,
          },
          ["{"] = {
            add = function() return { { "{" }, { "}" } } end,
          },
          ["["] = {
            add = function() return { { "[" }, { "]" } } end,
          },
          ["<"] = {
            add = function() return { { "<" }, { ">" } } end,
          },
        },
      }
    end,
  },
}

Upvotes: 0

Michael Berkowski
Michael Berkowski

Reputation: 270607

If you type S(, it will be surrounded by spaces. However if you use the closing ) instead S) it will not be surrounded by spaces.

This applies of course to all bracket pair surroundings, <> [] {} (), not merely to (), although the behavior of S< is such that it expects a tag enclosure so only S> is able to surround as <>.

Upvotes: 284

Ahmed Masud
Ahmed Masud

Reputation: 22372

When you use the surround plugin you can use:

cs) instead of cs( to surround without space :).

Upvotes: 32

Related Questions