Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make use nerdcommenter to give extra space after #

I am a vim user and has nerdcommenter plugin, the problem is when I use <leader>c<space> to comment out code (also block of code), it prefix # right in front of the code, but pep8 style checker is complaining that I should have a space after the #

eg.

#string = 'abc'

but I want it to comment to:

# string = 'abc'
like image 343
James Lin Avatar asked Aug 13 '14 06:08

James Lin


People also ask

How do you use nerd commenter?

@IngoKarkatNote: You don't need to hold down the key, just press it like any other key, and release it. Completely the wrong advice for the original question! With NerdCommenter, you DO have to hold down the <leader> key. Otherwise, as OP found, you just end up activating 'change' mode instead.

What is NerdCommenter?

The NERD Commenter is an indispensable tool when programming in VIM. It understands like a zillion different file types and properly comments each. It can handle single line, multi line, partial line commenting as well as nesting. If you're programming in VIM you really should be using it. It is simple enough to use.


2 Answers

I found that adding the following to my .vimrc was helpful.

let NERDSpaceDelims=1

This adds the desired extra space for all languages (see "NERDSpaceDelims" at https://github.com/scrooloose/nerdcommenter/blob/master/doc/NERD_commenter.txt)

like image 137
James Lawson Avatar answered Nov 16 '22 01:11

James Lawson


It appears that the delimiters are hardcoded in the /plugin/NERD_commenter.vim file, starting on line 67. You should be able to change '#' to '# ' for the filetypes that you wish to modify.

UPDATE: I found a more intended and more preferred way of accomplishing this. The plugin has code to handle what it calls CustomDelimiters. You can use something like this in your vimrc to accomplish the same thing as above in a more visible and transferable way:

let g:NERDCustomDelimiters = { 'py' : { 'left': '# ', 'leftAlt': '', 'rightAlt': '' }}
like image 37
bhekman Avatar answered Nov 16 '22 00:11

bhekman