preservim / nerdcommenter

Vim plugin for intensely nerdy commenting powers
Creative Commons Zero v1.0 Universal
4.99k stars 450 forks source link

fix: can't uncomment in sexy mode with NERDCompactSexyComs=1 for lua #451

Closed kevinhwang91 closed 3 years ago

kevinhwang91 commented 3 years ago

reproduce issue:

  1. open lua file;
  2. run ex let g:NERDCompactSexyComs = 1;
  3. enter visual mode and select multiple lines;
  4. <leader>cs;
  5. <leader>cu;

solve this issue by escaping [ and ].

alerque commented 3 years ago

Thanks for taking the time to contribute this. I'd definitely like to see it fixed. Before I merge however I'd like to understand how this will/won't affect other languages and issues. We've had some uncommenting issues reported before that we've never gotten around to fixing and I wonder how related this is. See e.g. #339, #341, #68, #295, #291, #74, #150, and maybe others.

At the very least this is probably a fix for #150, but lets also determine its impact on other issues.

kevinhwang91 commented 3 years ago

I think it's not related above issues, this issue is caused by https://github.com/preservim/nerdcommenter/blob/119b99d1662113a588734e3666213d246e50900d/plugin/NERD_commenter.vim#L2257-L2259

theLine value at the lastline looks like [ lastline ]]. In lua, '^[ \t]*' . sexyComMarker . '.*' . right = '^[ \t]*' . '[' . '.*' . ']]'. Without escaping [ and ], ^[ \t]*[.*]] can't match [ lastline ]].

This PR can't solve other issues but in order to fix the match for left and right.