1

I've asked a similar question in the past but haven't been able to solve it in too nice a manner. the only way I've been able to figure out how to change the delimiter is by modifying the NERDCommenter source itself:

# plugin/NERD_commenter.vim
let s:delimiterMap = {
    ...
    \ 'asm': { 'left': '#', 'leftAlt': ';' },
    ...
}

I would prefer to do something like this so it sits in my vimrc (or some other place so that if I move this to another machine it still works):

augroup AsmComments
   autocmd!
   autocmd Filetype asm let b:NERDCommenterDelims['left'] = '#'
augroup END

What would be the proper way to do this?


Update: By the way, I just typed in the following command (in the question) and pasted that into vim and it worked, so I think my problem should be fixed :)

1

Set g:NERDCustomDelimiters to a Dict with your overrides. You can set it in your vimrc:

let g:NERDCustomDelimiters = {
    \ 'asm': { 'left': '#', 'leftAlt': ';' }
    \ }

If this variable is defined when NERDCommenter is loaded, it will extend its delimiter map with it.

NERDCommenter also documents this variable under its :help 'NERDCustomDelimiters':

Use this option if you have new filetypes you want the script to handle, or if you want to override the default delimiters of a filetype.


The problem with overriding b:NERDCommenterDelims, as you suggested in the question, is that it needs to happen after the autocmd from NERDCommenter that initially sets it, so that block is unlikely to work if set in your vimrc...

You could make it work by storing it in a after/ directory, for instance ~/.vim/after/plugin/nerd_commenter_overrides.vim or similar.

(Ideally, creating an ftplugin named asm.vim would be better than creating an autocmd explicitly, but I'm afraid in this case it would probably get executed before the autocmd from NERDCommenter and wouldn't work either... In any case, the global Dict override is the way to go!)

| improve this answer | |
  • 1
    Thanks, this is great. The only solution that I found that works consistently -- thanks! – David542 Aug 23 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.