Search code examples
vimautocmd

Toggle NERDCommenter to Alternative Value Based on File Type


I'd like to configure NERDCommenter in vim to use the alternative comment styles for certain file types. What is the correct way to do this. I can't figure out how to call into the plugin code from the autocmd. What I'm trying to do is something like this:

autocmd FileType dosbatch :call NERDCommenterAltDelims

The above fails to work, but I found out I can get the function name with the command:

map <Plug>NERDCommenterAltDelims

that returns:

:call <SNR>17_SwitchToAlternativeDelimiters(1)<CR>

Is there some way to use the map command to execute the value of the map?


Solution

  • Alternatively, why don't you just switch the default and alt definitions for the dosbatch filetype, as NERDCommenter offers this extension point. Put the following into your ~/.vimrc; it must be executed before plugin/NERDCommenter.vim.

    let g:NERDCustomDelimiters = {'dosbatch': { 'left': '::', 'leftAlt': 'REM ' }}