3

I use vi in Linux to edit e.g. JSP files.

The code is not syntax highlighted. I think this should be possible to enable, but I haven't found out how. Is this possible to do in vi?

update1:

# vi --version
VIM - Vi IMproved 7.0 (2006 May 7, compiled Jul 2 2009 17:46:42)

update2:

i tried to open files with nano through Putty ssh according mnmnc answer but unfortunately result is not change. I'm not change html.nanorc file and it now have next text

syntax "html" "\.html$"
color blue start="<" end=">"
color red "&[^;[[:space:]]]*;"
8
  • lighted means you are telling about colour?
    – max
    Aug 23, 2012 at 6:36
  • yep, syntax highlighter Aug 23, 2012 at 6:37
  • for that use vim not vi
    – max
    Aug 23, 2012 at 6:39
  • i have problem with installing vim to server because i didn't have enough permissions. Aug 23, 2012 at 6:42
  • Which version of vi did you installed? vi --version might help.
    – Yai0Phah
    Aug 23, 2012 at 6:48

4 Answers 4

1

Why not use nano?

enter image description here

If you actually got VI and not VIM, nano has pretty good syntax highlighting capabilities based on a simple regular expression. Configurable for multiple languages.

Look in the /bin/nano /usr/bin/nano if you have it installed. It should be in there. Almost every linux has it.

perform cat /etc/nanorc this is a configuration script for nano. You should have it. It contains lines similar to this one: include "/usr/share/nano/html.nanorc" and the file /usr/share/nano/html.nanorc contains specification syntax highlighting.

for example:

syntax "html" "\.html$"
color brightcyan start="<" end=">"
color brightred start="<script" end="</script>"
color red "&[^;[[:space:]]]*;"

also you can place .nanorc file in you profile directory to overwrite the global settings.

If it is still not working then I think the fault is on the XShell side. Switch to Putty and check again. In the Putty window you will have options on the left hand side. There will be Window->Colours option. enter image description here

Make sure you have three first checkboxes ticked. It will work for sure. I think XShell made the output monochromatic for you.

9
  • so i've try it but it looks like that it's not work too or not enabled yet. One question. Can connection to server through ssh have any influence in this case? Aug 23, 2012 at 7:44
  • nano should especially work via SSH connection. I'm using it myself this way. You should give us an idea what kind of Linux are you using. You can try to find nano by typing "locate nano" or "whereis nano" commands.
    – mnmnc
    Aug 23, 2012 at 7:49
  • i have os Linux 2.6.18-194.el5 EDT 2010 x86_64 GNU/Linux, i use XShell as ssh client Aug 23, 2012 at 7:57
  • I do not think it matters what ssh client are you using. Once connected the environment on the other side is the same. Look in the /bin/nano /usr/bin/nano if you have it installed. It should be in there. Almost every linux has it.
    – mnmnc
    Aug 23, 2012 at 8:52
  • 1
    I think the fault is on the XShell side. Switch to Putty and check again. In the putty window you will have options on the left hand side. There will be Window->Colours option. Make sure you have three first checkboxes ticked. It will work for sure. I think XShell made the output monochromatic for you.
    – mnmnc
    Aug 23, 2012 at 10:03
2

vi on Linux is almost certainly actually vim. You can check this as follows

# vi --version
VIM - Vi IMproved 7.0 (2006 May 7, compiled Mar  5 2011 21:36:07)

vim does support colour syntax highlighting. However it only does so on terminals that support ANSI colour not on monochrome terminals. Check the value of your TERM variable.

# echo $TERM
xterm

Then check if that terminal type supports colours

# infocmp xterm | grep color
        colors#8, cols#80, it#8, lines#24, pairs#64,

In a vim session you can also change this setting

:set term=color_xterm
:set term=ansi

etc

Syntax highlighting only works for files that vim recognises as being a file for which it has a set of highlighting rules. If you read vim's help, you can find out how to add your own highlighting rules files

1
  • thnx for information,i'll try Aug 23, 2012 at 17:31
1

This is vi

enter image description here

This is vim

vim means improved version of vi

enter image description here

5
  • ok, thats means that its impossible in vi, so sad Aug 23, 2012 at 6:46
  • If I get any alternate method then I will inform you ok.
    – max
    Aug 23, 2012 at 6:48
  • it'll be great, thnx raj Aug 23, 2012 at 6:49
  • use emacs It will highlight the colour
    – max
    Aug 23, 2012 at 7:21
  • thnx for advice Aug 23, 2012 at 7:22
0

You may need to explicitly turn highlighting on. Try

:syntax on

and

:help syntax
2
  • Thnx for answer. i try :syntax on no effect. :help syntax sais that E433: No tags file E149: Sorry, no help for syntax. It looks like that this module is not installed Aug 23, 2012 at 7:29
  • 1
    @BrianAgnew Yoshi got a monochromatic shell output (green on black) - probably because of XShell configuration. It's not the matter of VI/VIM config or lack of the editor itself.
    – mnmnc
    Aug 23, 2012 at 10:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .