preservim / nerdcommenter

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

[Bug] Vim file with inline comment and spaces before line can't be uncommented normally. #491

Closed hungpham3112 closed 1 year ago

hungpham3112 commented 2 years ago

https://user-images.githubusercontent.com/75968004/161737074-77917361-5998-46f1-a765-42eab1b096b6.mp4

I am using <Space>c for NERDCommentToggle

Konstantin-Glukhov commented 1 year ago

Any ETA on fixing this?

alerque commented 1 year ago

Contributions are welcome, this is an open source project not maintained by the original author and now a maintained by a community group. I or somebody is usually able to carve out time to facilitate PRs, but personally I don't have a lot of development to dig into issues that don't affect me directly.

Konstantin-Glukhov commented 1 year ago

Ok, I am willing to contribute. I have found the bug on line 2539. I propose the following change:

@@ -2534,9 +2534,8 @@
             return 0
         endif

-        "if the delimiter is on the very first char of the line or is the
-        "first non-tab/space char on the line then it is a valid comment delimiter
-        if a:delIndx ==# 0 || a:line =~# "^\s\\{" . a:delIndx . "\\}\".*$"
+        "if the delimiter is the first non-whitespace character it is valid
+        if a:line =~ '^\s*"'
             return 1
         endif

I created a Pull Request #510

Konstantin-Glukhov commented 1 year ago

OK, I made the requested change. Sorry that I am not familiar with the build process and lint warnings, though I don't understand why case insensitivity is a requirement in this case. I also think it is silly to talk about CPU optimization for a commenter. It is not like it is running in a loop with million iterations. :-)

alerque commented 1 year ago

In the case of this regex it doesn't make any difference at all, but we have to keep the linter happy anyway otherwise we won't notice when it throws actually meaningful warnings (which it does sometimes).

I've actually been bothered by the performance of this plugin when commenting large blocks or programmatically commenting something over a large code base, but agree this case isn't going to even register on the scale since it is trivial anyway on only for VIM syntax. If you have thousands of lines of VIM script you are commenting out on a regular bases you are doing something else wrong anyway ;-)