VIM

1. vim ist besser als emacs 2. goto 1.

⇒ vim ist der editor deiner wahl :!:

Syntax Highlighting

Syntax Highlighting in HEREDOCS

When for instance writing mathematica scripts as a HEREDOC within a shell script to be passed to the mathematica kernel - as shown in the example below - it can be annoying reading the mathematica part for usually only shell script syntax highlighting is activated. The heredoc is then shown in completely one color, whereas the shell commands are fancyly coloured.

math -run "mymmavar1=\"Hello\"; mymmavar2=\" World!\""  <<'MMASH' 
          (* this is within the heredoc *)
          (* we can write real mathamatica code here *)
          (* we also can use the initialized variables *)
          Print[StringJoin[mymmavar1,mymmavar2]]
MMASH

To tell vim to recognise the mathematica code within the heredoc, we have to tell him by creating the file

~/.vim/after/syntax/sh.vim

let s:bcs = b:current_syntax
unlet b:current_syntax
syntax include @MMA syntax/mma.vim
let b:current_syntax = s:bcs
syntax region shHereDoc matchgroup=shRedir start=+<<\z(MMASH\)+   matchgroup=shRedir end=+^\z1$+ contains=@MMA
syntax region shHereDoc matchgroup=shRedir start=+<<'\z(MMASH\)'+ matchgroup=shRedir end=+^\z1$+ contains=@MMA 

Now whenever a heredoc within a shell script begins with MMASH, vim recognises it as mathematica code highlighting the syntax correctly.


QR-Code
QR-Code VIM (erstellt für aktuelle Seite)