?
Solved

:highlight Comment in Vim Editor

Posted on 2011-05-05
36
Medium Priority
?
579 Views
Last Modified: 2012-05-11
Hi, how can I highlight the comment. I tried by using  syntax on.
its was highlights before and i guess i did something to disable that and im not really sure what. Thank you.
0
Comment
Question by:Nura111
  • 18
  • 14
  • 4
36 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 35702093
Get a good color scheme.  It would do it for you.

Actually, the definition of comment is different for different languages.

For example for C-language, you can do something like

highlight cComment ctermfg=Green guifg=Green
0
 

Author Comment

by:Nura111
ID: 35702106
its just an text file with comment #
its the slow-queries-log file
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702115
Get a wonderful colorscheme of your choice from here

http://vimcolorschemetest.googlecode.com/svn/html/index-c.html
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 31

Expert Comment

by:farzanj
ID: 35702127
Ok, then a Perl like colorscheme or shell kind of colorscheme would be suitable for you
http://vimcolorschemetest.googlecode.com/svn/html/index-pl.html
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702172
Also try this:
syntax on
highlight Comment term=bold ctermfg=6 guifg=Cyan
0
 

Author Comment

by:Nura111
ID: 35702180
Im not really sure what am i suppose to do with that (Im pretty new to vim and linux)
the file that i want to change the highlights is a log-queries-file its a file that mysql is generate no me. I dont want to add there things i was thinking more of changing it through the command line  
0
 

Author Comment

by:Nura111
ID: 35702203
tried syntax on
highlight Comment term=bold ctermfg=6 guifg=Cyan
it doesnt do anything
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702217
Are you in Linux/Unix?

DO NOT touch any files.

Your personal file for vim is

~/.vimrc

That is .vimrc file in your home directory (Linux/Unix)

In this file you can put these lines

For a temporary change, you can put these lines in the command mode--downside of course it would go away when you exit the editor

But just to test you can do

:set syntax on
:set highlight Comment term=bold ctermfg=6 guifg=Cyan
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702229
Ok, try

:colo blue


Does this work?

This is to be done in the command mode just like you write

:wq
0
 

Author Comment

by:Nura111
ID: 35702260
its does highlights text in other files and it did highlights for this one but from some reason its not now.

and when im trying to add  it to the command mode it say E518: Unknown option: on
 
and yes i have linux
0
 

Author Comment

by:Nura111
ID: 35702267
yes its change the background to blue
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702269
Ok

It is

:syntax on
:highlight Comment term=bold ctermfg=6 guifg=Cyan
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702294
Ok,

Write these lines in your .vimrc file in your home directory.

Files should have an extension name like .pl or .sh

Linux doesn't care but Vim recognizes files this way.
0
 

Author Comment

by:Nura111
ID: 35702296
no not doing anything
0
 

Author Comment

by:Nura111
ID: 35702319
I cant seem to find .vimrc file
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702337
Create it.

Just create a file

~/.vimrc

And type in it

se nu

Save and exit

Then open a file in it and tell me what you see.
0
 

Author Comment

by:Nura111
ID: 35702361

se nu
0
 

Author Comment

by:Nura111
ID: 35702362
i created it in home/myname
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702367
Now when you open any file, you should see something new, what is it?
0
 

Author Comment

by:Nura111
ID: 35702411
when im opening the file the only thing there is what i wrote: se nu
this is how i opened it:
pico ~/.vimrc
and i wrote inside se nu and saved it with ct X
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702424
Why are you using pico??

Why are you not doing

vim ~/.vimrc

or

gvim ~/.vimrc

pico is a totally different editor.

Use gvim
0
 

Author Comment

by:Nura111
ID: 35702451
im sorry!! im really really new at this

so it doent know gvim i
so i opened with vim ~/.vimrc
its already have there at first line se nu i saved and ouit and now what?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702464
What kind of Linux is it?

If you open any other file, do you see any line numbers at all?

I am suspecting you don't have a fully installed version.  Install gvim also.  That is much better if you want life to be colorful.
0
 

Author Comment

by:Nura111
ID: 35702551
its ubuntu and yes i see numbers of lines
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702562
Can you install gvim?

0
 

Author Comment

by:Nura111
ID: 35702627
i installed it
0
 

Author Comment

by:Nura111
ID: 35702636
but i dont think i did it right becaus eit tell me:

You must choose one to install.
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
Need to get 0B of archives. After unpacking 0B will be used.

i tried to install it as follows:
sudo aptitude update
sudo aptitude install gvim
gvim.


as i mentioned im pretty new isnt there is anyway for now just to change the specific files i need throw the command ?

Thank you for the help!
0
 
LVL 38

Accepted Solution

by:
wesly_chen earned 2000 total points
ID: 35702642
> how can I highlight the comment
> its just an text file with comment #
> its the slow-queries-log file

$ echo "syntax on" >> ~/.vimrc
$ echo 'syntax match group1 /^#.*/' >> ~/.vimrc
$ echo "highlight link group1 Comment" >> ~/.vimrc

Then use vi to open the log file....
0
 

Author Comment

by:Nura111
ID: 35702661
where should i write those lines please??
<
$ echo "syntax on" >> ~/.vimrc
$ echo 'syntax match group1 /^#.*/' >> ~/.vimrc
$ echo "highlight link group1 Comment" >> ~/.vimrc
>
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35702676
Just on the shell.  He is basically telling you to write it on the .vimrc file.
0
 

Author Comment

by:Nura111
ID: 35702691
im writing it without the $ because its no recognizing it is that ok?
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 35702695
Right, no $
0
 

Author Comment

by:Nura111
ID: 35702723
yes its working thank you!  now  that changed it to all files in general right?
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 35702732
Right. But only for the user have that ~/.vimrc.
0
 

Author Comment

by:Nura111
ID: 35702746
ok but if i put in home doesn't it mean that all users will have it?
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 35702758
No, only for that user.
But you can do it for globally by changing /etc/vimrc  (not recommended)

Issue the two commands:

sudo  echo 'syntax match group1 /^#.*/' >> /etc/vimrc
sudo echo "highlight link group1 Comment" >> /etc/vimrc
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question