vim and python comments

August 12, 2009

I’m currently undergoing a profound revision (read “cleanup”) of my .vimrc and I recently had to choose a decent plug-in to comment python code.

the best so far is EnhancedCommentify. it’s highly configurable, powerful and it supports a different number of languages (not only python).

the only one thing that wasn’t easy to setup if the behaviour described here: being able to comment a block, respecting the indent, in both visual and normal mode.

a clean solution, without the need to define any function is to stick these lines into your .vimrc:


let g:EnhCommentifyPretty='Yes'
let g:EnhCommentifyRespectIndent='Yes'
let g:EnhCommentifyUserBindings="Yes"
let g:EnhCommentifyUseBlockIndent='Yes'


vmap ,c (Plug)VisualComment
vmap ,d (Plug)VisualDeComment
vmap ,g (Plug)VisualTraditional
vmap ,f (Plug)VisualFirstLine
nmap ,c (Plug)Comment
nmap ,d (Plug)DeComment
nmap ,g (Plug)Traditional
nmap ,f (Plug)FirstLine

(but remember to change “(” to “<” and “)” to “>” — wordpress is strict about “<” and “>”…)

enjoy!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: