Search code examples
vimnerdcommenter

Vim Nerdcommenter custom delimiters does not work


I am attempting to follow the advice here:

Vim NerdCommenter: adding a new filetype in vimrc

and here:

MacVim NERDCommenter, how to specify alternative delimiters

When I declare my own CustomDelimiters in my .vimrc file, the Nerdcommenter does not appear to recognize them.

I have put the lines

let g:NERDCustomDelimiters = {
    \ 'blahblah': { 'left': '#'}
\ }

Into my .vimrc, but whenever I open a file called a.blahblah, I still get the default /*...*/ commenting behavior. If I attempt to use <Leader>ca, I am told

"NERDCommenter:Cannot use alternative delimiters, none are specified"

I have moved the above lines to the head and tail of my .vimrc file, but I get the same behavior.

Thank you for your help.


Solution

  • When you set the g:NERDCustomDelimiters, you ask the NERD-Commenter plugin to change the delimiters for some specific file types.

    Unless you added something for this, blahblah is not a known file type, so when you edit a.blahblah, no file type will be defined, and the NERD-Commenter delimiters will be the default ones.

    After opening a file, you can manually change its current file type by doing:

    set ft=blahblah
    

    Then your example should work.