kylechui / nvim-surround

Add/change/delete surrounding delimiter pairs with ease. Written with :heart: in Lua.
MIT License
2.92k stars 60 forks source link

nvim-surround adds spurious indentation #233

Closed gregorias closed 1 year ago

gregorias commented 1 year ago

Checklist

Neovim Version

v0.8.3

Plugin Version

Nightly (Beta)

Minimal Configuration

vim.o.smartindent = true

-- | Fetches Lazy if not present.
local function bootstrap_lazy()
  local lazypath = vim.fn.stdpath('data')..'/lazy/lazy.nvim'
  if not vim.loop.fs_stat(lazypath) then
    vim.fn.system{
      'git', 'clone',
      '--filter=blob:none',
      'https://github.com/folke/lazy.nvim.git',
      '--branch=stable',
      lazypath,
    }
  end
  vim.opt.rtp:prepend(lazypath)
end
bootstrap_lazy()

require'lazy'.setup({
  { 'kylechui/nvim-surround',
    config=function() require('nvim-surround').setup({}) end,
  },
  }
)

Sample Buffer

data Foo = Foo
  { fooA :: !Decimal
  , fooB :: !Decimal
  }

Keystroke Sequence

Put the cursor before D on the 3rd line, then

  viw -- Select `Decimal`
  S)  -- Surround with )

Expected behavior

The buffer looks like this:

data Foo = Foo
  { fooA :: !Decimal
  , fooB :: !(Decimal)
  }

Actual behavior

The buffer looks like this:

data Foo = Foo
  { fooA :: !Decimal
      , fooB :: !(Decimal)
  }

Additional context

Possibly adding a check not to indent single line selection would be the right behavior.

I don't think it's not an error with not setting tabstop correctly. If I do

vim.o.expandtab = true
vim.o.tabstop = 2
vim.o.shiftwidth = 2

then I still get spurious indentation of 2 additional spaces.

gregorias commented 1 year ago

Another way I addressed this issue is by configuring indentation for Haskell correctly with https://github.com/itchyny/vim-haskell-indent and not rely on smartindent.

Nevertheless, perhaps it's worth considering not intending single line surrounds.