LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 11-13-2012, 11:04 AM   #1
kaiserkarl13
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
Code:
#! /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:

Code:
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
endif

syntax include @AwkSyntax syntax/awk.vim

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

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.
 
  


Reply

Tags
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 06:43 PM
VIM Syntax Highlighting JMJ_coder Programming 3 03-05-2008 05:37 PM
[SOLVED] vim without syntax highlighting lord_didger Debian 5 11-18-2006 02:29 PM
vim syntax highlighting MiniMe001 Linux - General 2 06-19-2005 12:08 PM
Vim syntax highlighting NSKL Linux - Software 2 11-09-2002 03:39 AM


All times are GMT -5. The time now is 07:36 AM.

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