You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have comment_empty_trim_whitespace = true but doing a simple comment/uncomment on something like this leaves the middle line with spaces when only the inner block is selected
iftruethenlocalfoo=1-- visual mode from herefoo=foo+1-- to hereend
If I select the whole top level statement it works, but if I comment out the middle part it does not, and leaves as many spaces as it was initially indented. This is undesirable, because at least in my experience one does not want whitespace on empty lines in indented code.
I dug into the code a bit and found that the pattern is matched, but the replacement seems wrong
functionM.uncomment_line(l, left, right, comment_empty_trim_whitespace)
localline=lifrightandright~="" thenline=line:gsub(vim.pesc(right) .."$", "")
returnline:gsub(vim.pesc(left), "", 1)
endifcomment_empty_trim_whitespaceandleft:match("%s+$") thenlocalleft_nw=left:match("^(%S+)%s+$")
ifline:match("^%s*" ..left_nw.."$") thenprint("THIS GETS PRINTED EXACTLY ONCE, BUT NO REPLACEMENT")
returnline:gsub(vim.pesc(left_nw), "", 1)
endendreturnline:gsub(vim.pesc(left), "", 1)
end
fixes it for me. I don't know much about neovim's APIs, so not sure if this is the best way to do it, but it does seem to work. Testing it even on some bigger code seems to produce the expected results.
The text was updated successfully, but these errors were encountered:
darthdeus
changed the title
Whitespace trim doesn't work
Whitespace trim doesn't work on indented blocks as expected
Nov 24, 2023
I have
comment_empty_trim_whitespace = true
but doing a simple comment/uncomment on something like this leaves the middle line with spaces when only the inner block is selectedIf I select the whole top level statement it works, but if I comment out the middle part it does not, and leaves as many spaces as it was initially indented. This is undesirable, because at least in my experience one does not want whitespace on empty lines in indented code.
I dug into the code a bit and found that the pattern is matched, but the replacement seems wrong
Replacing
with
fixes it for me. I don't know much about neovim's APIs, so not sure if this is the best way to do it, but it does seem to work. Testing it even on some bigger code seems to produce the expected results.
The text was updated successfully, but these errors were encountered: