preservim / nerdcommenter

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

Uncommenting does not work when left delimiter starts with backslash #498

Open nano-o opened 2 years ago

nano-o commented 2 years ago

Uncommenting lines starting with \* does not work in tla files with the following configuration:

let g:NERDCustomDelimiters = { 'tla': { 'left': '\\*', 'leftAlt': '(*', 'rightAlt': '*)' } }
alerque commented 2 years ago

What happens — is this something about backslash escaping that isn't working right?

nano-o commented 2 years ago

The uncommenting command just doesn't do anything. To reproduce, set g:NERDCustomDelimiters = { 'tla': { 'left': '\\*', 'leftAlt': '(*', 'rightAlt': '*)' } } Then create a file myfile.tla with contents:

\* this is a comment

Set filetype to tla. Now try the uncommenting command. It does not work.

alerque commented 2 years ago
let g:NERDCustomDelimiters = { 'tla': { 'left': '\\*', 'leftAlt': '(*', 'rightAlt': '*)' } }

Using this (which as of your PR #497 is merged so you don't need to add it to your configs, just update your plugins) produces a commented line prefixed with \\* not \* as in your example file. Of course it won't reverse. It works for me to uncomment the lines it comments. Did you use the wrong comment string or mistake when escaping backslashes are needed?

nano-o commented 2 years ago

Okay that's strange. I removed the line above from my config and update the plugin. The commenting command <Leader>c<space> produces \* and not \\*. But you're right that if I start a line with \\* then uncommenting works. I'm using neovim btw; is that the problem?

nano-o commented 2 years ago

Well, I get the same behavior in vim. If I start with

this is a comment

and hit <Leader>c<space>, I get

\* this is a comment

Hitting <Leader>c<space> again I get

\* \* this is a comment

If I start with

\\* this is a comment

and hit <Leader>c<space>, I get

this is a comment
alerque commented 2 years ago

I'm in Neovim too. <Leader>c<Space> only toggles \\* prefixes for me, using the current state of this plugin with no modifications.

nano-o commented 2 years ago

Okay, maybe it's something platform specific. I just tried in a fresh Ubuntu jammy docker image with a fresh vim install where the only thing I did is install nerdcommenter with vimplug. I get the behavior I described above.