Frage

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?

War es hilfreich?

Lösung

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 ' }}

Andere Tipps

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.

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.

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top