`LS_SELECT_DEDENT` removes interior whitespace from characterwise selections

Open Beginner friendly
#1,452 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
lua
Domain
tooling

Research direction

Read lua/luasnip/util/select.lua around lines 116-130, focusing on the characterwise selection path and its intermediate-line loop. Run the minimal Neovim reproduction and compare visual, linewise, and blockwise selections; done means dedenting removes only applicable leading indentation while preserving interior whitespace such as the gap in "keep gap".

Written by the indexing model from the issue text.

Description

Environment

  • LuaSnip: 0abc8f390b278c3b4aabc4c004ac8a088b65cf24 (current master when checked on 2026-09-16).
  • Neovim: 0.13.0-dev-1644+gaed60b8a53.

Minimal reproduction

Start Neovim without a user configuration, add a LuaSnip checkout to runtimepath, and configure its built-in selection mapping:

vim.opt.runtimepath:prepend("/path/to/LuaSnip")
vim.keymap.set("x", "<F5>", require("luasnip").cut_keys)

And the file content:

    first
      keep    gap
    last

From Normal mode, type gg^vjj$ (^v is not Ctrl + V), then press <F5>. Leave Insert mode and inspect:

:lua print(vim.inspect(vim.fn.visualmode()))
:lua print(vim.inspect(vim.b.LUASNIP_SELECT_DEDENT))

Expected:

{ "first", "  keep    gap", "last" }

Actual:

{ "first", "  keepgap", "last" }

The four spaces inside keep gap are deleted even though they are part of the selected content, not indentation. LUASNIP_SELECT_RAW still contains them.

Starting again from the original text, the three selection modes give this comparison:

Selection keys before <F5> visualmode() Middle line after dedenting
gg^vjj$ "v" " keepgap" (the bug)
ggVjj "V" " keep gap"
gg<C-v>jj$ "\22" " keep gap"

Relevant implementation

The characterwise path uses unanchored gsub(min_indent, "") calls in select.lua. In particular, the loop over intermediate lines removes every matching run, including whitespace inside the line body. The linewise path anchors its removal at the beginning of each line.

https://github.com/L3MON4D3/LuaSnip/blob/0abc8f390b278c3b4aabc4c004ac8a088b65cf24/lua/luasnip/util/select.lua#L116-L130

The expected behavior is to remove only the applicable leading indentation and preserve the rest of the selected content.

Dominant language
Lua
Stars
4.4k
Forks
269
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from L3MON4D3/LuaSnip

All issues in L3MON4D3/LuaSnip

Similar issues

More Lua issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.