2

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?

Charles
  • 50,943
  • 13
  • 104
  • 142
cmcginty
  • 113,384
  • 42
  • 163
  • 163

4 Answers4

1

Since there is only the script-local function, you have to invoke the provided <Plug> mapping via :normal:

:autocmd FileType dosbatch execute "normal \<Plug>NERDCommenterAltDelims"

To suppress the Now using ... to delimit comments message, use silent execute instead.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Great answer since it calls the function in question. The only problem, is that when the autocmd executes, I don't think the plugin has loaded yet. Is there anyway to chain this with VimEnter? – cmcginty Sep 24 '12 at 19:35
  • Huh? The `FileType` event is fired whenever a batch file is detected. The inital load of plugins happened before that (and before `VimEnter` on startup. Anyway, I would prefer my other solution because it only needs to run once. – Ingo Karkat Sep 25 '12 at 06:38
1

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 ' }}
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
0

Building off of @ingo-karkat answer:

autocmd FileType dosbatch autocmd VimEnter * execute "normal \<Plug>NERDCommenterAltDelims"

My vimscript skills are non-existant, so there might be a cleaner way to do this. Feel free to improve upon it.

cmcginty
  • 113,384
  • 42
  • 163
  • 163
0

It seems that there is now a new better way to use the functionality of NERDCommenter in our own mappings:

call NERDComment('n', 'altDelims')

See:

:h NERDComNERDComment
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985