commented.nvim
commented.nvim copied to clipboard
support left aligned commenting
This is the best comment plugin for me. nvim-comment and kommentary still need improvement. The only missing feature in this plugin is left aligned commenting. Some code formater will align comments. For example, python format black will turn
# if i==1:
# print(2)
into
# if i==1:
# print(2)
lua's format lua-format will turn
--if a == 1 then
--a = 2
--a = 2
--end
into
-- if a == 1 then
-- a = 2
-- a = 2
-- end
This makes coding tough, and left aligned commenting can avoid this issue. Both nvim-comment and kommentary choose left aligned commenting. and nerdcommenter binds <leader>cl to it.
Also, when <leader>cl is used to uncomment, various spacing handling should be skiped.
Thank you for your clear explanation for this behavior. I haven't implemented this feature(out of laziness), but I guess it will not be too difficult to do.
@tkkcc The feature has been implemented in https://github.com/winston0410/commented.nvim/commit/994ca1e2213853cb54e6b36598e9222e57c8b52e
I haven't made the documentation yet, and it will be great if you could help out with that :)
Thanks. I tried the trim_leading_whitespace=true option, but what it did is just the issue it self. There seems a misunderstanding. For left aligned commenting, the comment string is left aligned, but original code's indention is preserved, so the code block will not be unexpectedly modified by code formatter during commenting and uncommenting. For example, commenting should turn
if i==1:
print(2)
into
-- if i==1:
-- print(2)
then uncommenting should turn
-- if i==1:
-- print(2)
into
if i==1:
print(2)
This is the default logic in vim-commentary, nvim-comment and kommentary, you can try any of them if you want.
@tkkcc But isn't that the default behavior for commented (trim_leading_whitespace = false)? Can you provide a dummy code that I can use it for testing?
commented by default will turn
if i==1:
print(2)
into
-- if i==1:
-- print(2)
@tkkcc Oh I get what you mean now. Let me fix this today.
@tkkcc check https://github.com/winston0410/commented.nvim/commit/60efd1bf3c06b2190511e6ad4b9ae9f08e1b41a0
Current issue is the comment string is not context aware. I get
if true:
# if i == 1:
# print(2)
expect
if true:
# if i == 1:
# print(2)
@tkkcc Right thank you for pointing that out. I guess it will take more on work on this one.
Please consider reopening the issue
@ahmedkhalf Reopened, as this is not fixed yet.