Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-13-2012, 10:04 AM   #1
LQ Newbie
Registered: Jan 2010
Distribution: Fedora
Posts: 23

Rep: Reputation: 4
VIM syntax highlighting: Use of AWK syntax inside shell scripts

I've been trying to add a simple script inside ~/.vim/after/syntax/sh.vim that will use the syntax highlighting for awk when the user does something like
#! /bin/sh
awk < myfile.txt "
  BEGIN {i=0}
  /stupid/ {$3 = ''; print; i = i + 1}
  END {print \"I found\", i, \"stupid people\"}
There are facilities to do this, of course, but I'm stumbling over the precise details. Here's what I have so far:

if exists('b:current_syntax')
    " Unset this, or the AWK syntax file thinks it's already loaded!
    let s:current_syntax = b:current_syntax
    unlet b:current_syntax

syntax include @AwkSyntax syntax/awk.vim

if exists('s:current_syntax')
    " Undo what we did before
    let b:current_syntax=s:current_syntax
    unlet b:current_syntax

syntax region AwkScript start=#\(^\s*g\=awk\(\s\+\p\+\)*\s\+\)\@<='#
\       end=#'# contains=@AwkSyntax matchgroup=SpecialComment
syntax region AwkScript end=#"# skip=#\\"#
\       start=#\(^\s*g\=awk\(\s\+\p\+\)*\s\+\)\@<="#
\       matchgroup=SpecialComment contains=@AwkSyntax
This works for the single-quote version, but not the double-quote version (it recognizes everything as an AWK string). I don't know how to resolve this issue. What it should do is start AWK syntax right AFTER the quotation mark (not ON it...) and avoid recognizing the entire string as a shell string. I can't seem to do both of these things at the same time.


awk, shell script, syntax, vim

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vim syntax highlighting Gortex Programming 1 08-18-2008 05:43 PM
VIM Syntax Highlighting JMJ_coder Programming 3 03-05-2008 04:37 PM
[SOLVED] vim without syntax highlighting lord_didger Debian 5 11-18-2006 01:29 PM
vim syntax highlighting MiniMe001 Linux - General 2 06-19-2005 11:08 AM
Vim syntax highlighting NSKL Linux - Software 2 11-09-2002 02:39 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration