Find the answer to your Linux question:
Results 1 to 4 of 4
When I edit a shell script as my regular user account, keywords within the script are colorful. Variables are dark blue, text inside double-quotes is pink, shell commands are yellow, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    3

    Colorful vi


    When I edit a shell script as my regular user account, keywords within the script are colorful. Variables are dark blue, text inside double-quotes is pink, shell commands are yellow, comments after a # are cyan.

    When I edit the same files using vi as root, there are no colors. My guess is that this is configured in .profile or .bash_profile or something like that in each user's home directory, but I cannot find the specific file. So, do anyone know how to make vi colorful for root as well?

    Thanks in advance...

  2. #2
    oz
    oz is offline
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,733
    Hello

    If you haven't tried it, I believe vim can display in color as root user but not sure about vi.

    Maybe someone else will have more info for you.
    oz

  3. #3
    Just Joined!
    Join Date
    Aug 2011
    Posts
    5
    you would be better suited using vim.

  4. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    First make sure vim is installed, as was suggested:
    Code:
    which vim
    If installed, it will likely be in /usr/bin/vim.

    Now as root, do this, in a terminal:
    Code:
    which vi
    if it reports an alias pointing to 'vim', then no changes needed there. if it reports 'vi', then put something like this in root's ~/.bashrc:
    Code:
    alias vi='/usr/bin/vim'
    now source the file, so that vi is aliased to vim.

    next, open a file as root with vi, say /etc/bashrc (so we know there is syntax highlighting to be able to see). in it turn on syntax highlighting with this:

    Code:
    :syntax on
    If the colors do not appear, then something is wrong - post back. But if the colors do appear, then quit out of vi and add something like this to your vim profile, ~/.vimrc:
    Code:
    syntax on
    That should do it.

    NOTE: some versions of Fedora/Red Hat would put a line in /etc/profile.d/vim.sh to not allow root users to alias vi to vim for some crazy ass reason.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •