Vim Comment Out Region

I had to comment and uncomment large portions of text.

After reading I added the following lines to my ~/.vimrc:

let b:comment_leader = '# '
au FileType haskell,vhdl,ada let b:comment_leader = '-- '
au FileType vim let b:comment_leader = '" '
au FileType c,cpp,java let b:comment_leader = '// '
au FileType sh,make let b:comment_leader = '# '
au FileType tex let b:comment_leader = '% '
noremap ,c :sil s/^/=escape(b:comment_leader,'\/')/:noh
noremap ,u :sil s/^\V=escape(b:comment_leader,'\/')//e:noh

Now I can select text (with V for visual lines) and press ,c for commenting and ,u for uncommenting the selected lines.

Trackback URL for this post:


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <br> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <fieldset> <legend> <h6> <span> <img> <div> <p>
  • Lines and paragraphs break automatically.

More information about formatting options

Refresh Type the characters you see in this picture.
Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.