Vim Tips Wiki
Register
Advertisement
Tip 1072 Printable Monobook Previous Next

created 2005 · complexity basic · author kamarali · version 6.0


Sometimes you get bugged with all the comments in your working file. With all the Fixes and Patches and previous comments, code looks miserable. I don't know whether there is any better way of getting rid of comments. This is not a generic tip that will work for all color settings. I don't know how I will get the background color of the currently active theme.

Anyone using Black background in Vim can use the following command:

:hi Comment guifg=black

Anyone using White background can try this:

:hi Comment guifg=white

Comments[]

For what it is worth, my preferred method to ignore comments is simply to fold them away. This way they are still easily accessible if I want, and I can leave comments that I want. However, the downside is (depending on your fold method, of course) it can be tedious to fold masses of comments.


My personal view is that these sort of history comments have no place in the code. Comments should only be what the code does now. They should also never be hidden - if they are of so little use that they can be hidden then they should be deleted.

Of course changes should be commented, but these should be as part of the Source Code Control system as they are checked in, not an integral part of the code.


Here is a small script which will work for all types of colors.

if !exists("ccolor")
  let ccolor = 0
  let comment_fg = synIDattr(synIDtrans(hlID("Comment")), "fg")
  let comment_bg = synIDattr(synIDtrans(hlID("Comment")), "bg")
  let background = synIDattr(synIDtrans(hlID("Normal")), "bg")
  execute "highlight Comment guifg=" background
  execute "highlight Comment guibg=" background
  exit
endif
if ccolor == 0
  let ccolor = 1
  execute "highlight Comment guifg=" comment_fg
  execute "highlight Comment guibg=" comment_bg
else
  let ccolor = 0
  let background = synIDattr(synIDtrans(hlID("Normal")), "bg")
  execute "highlight Comment guifg=" background
  execute "highlight Comment guibg=" background
endif
"check this comment

put this in some comment_color.vim

:so comment_color.vim will change shadow and unshadow comment, alternately.


Advertisement