ICS/Lotus (mostly), Linux, Travel, Skiing, Mixology, and Random Musing of Interest

 
Bill Malchisky
 

Archives

    Find me here…

  • Skype
  • Bleedyellow via Sametime
  • Linux School -- Syntax Highlighting in Vim

    Bill Malchisky  July 2 2013 01:00:00 AM
    Previously, we covered how to load vim and setup an alias to ensure you are using the latest and greatest feature set with this classic editor. One new feature that vim provides is syntax highlighting, which is quite valuable for administrators and developers. Now, your script files and system configuration files will automatically be color coordinated, making visual parsing easy.

    Syntax Highlighting with VIM

    One of the nice features is to be able to toggle syntax highlighting on/off within the session. This is helpful if you have a non-white background and would rather not redefine the dark blue color mapping when against a black background color in your terminal. The editor is smart enough to know when to enable highlighting for system configuration and script files, leaving the highlighting disabled for ordinary text files. If you are running Red Hat / Fedora / CentOS, this feature may be available for you already. Here is how you can check: $vim --version | grep syntax
    If you see "-syntax" (sans quotes) then you need to install vim-enhanced; whereas "+syntax" indicates enablement exists.

    The same test works with vi and can help you better understand if you are running the lightweight version of vim. Recall that on Ubuntu, you need to install vim, so here is the vi test, which is the editor provided by default:
    malchw@san-domino:~$ vi --version |grep syntax

    -statusline -sun_workshop
    -syntax -tag_binary -tag_old_static -tag_any_white

    If you lack the vi -> vim alias mentioned above, on RHEL, Fedora, and CentOS, typing $vi will actually start a lightweight vi session owned by vim and thus, syntax highlighting is unavailable. In my RHEL and CentOS VMs, the vi -> vim mapping exists, so I receive a syntax positive result when keying 'vi' as indicated below:
    [bill@localhost Documents]$ vi --version |grep syntax

    +signs +smartindent -sniff +startuptime +statusline -sun_workshop
    +syntax

    After installing vim on Ubuntu, syntax highlighting is available by default
    malchw@san-domino:~$ vim --version |grep syntax

    -sniff +startuptime +statusline -sun_workshop
    +syntax +tag_binary

    Here is the same file with syntax highlighting enabled and disabled. While editing a file, you can simply type :syntax off or :syntax on to toggle the feature.

    Image:Linux School -- Syntax Highlighting in Vim Image:Linux School -- Syntax Highlighting in Vim 

    Let me know if you have any questions. I find this feature to be quite helpful in debugging shell scripts and modifying configuration files.
    Comments

    1MR  7/3/2013 3:54:20 AM  Linux School -- Syntax Highlighting in Vim

    lol, never even thought of looking for this, but now that you've pointed it out, will use and will be useful. Thanks a lot !

    2Bill Malchisky  7/7/2013 12:22:15 AM  Linux School -- Syntax Highlighting in Vim

    Glad you found it useful. Enjoy!

    Powered by IBM Lotus Domino 8 | Lotus User Group | Get Firefox! | This blog is listed on Planet Lotus   IBM Certified

    © 2010 William Malchisky.