14. Mai 2008

Vim: Gnucap integration

Category: Computer — Kay Smarczewski @ 14:50

An example for the new coloring of GNUCap files in vim.In the past few weeks I has been engaged in circuit simulations. The first thing you will think of is for sure SPICE. Unfortunatly the license is subject to different views and restrictions: the non-commercial use of the software is for free, but this is not full open source in the “debian way of licensing”. Thats why i searched for alternatives and found GNUCap. This is a GPLed circuit simulator. But vim does not recognise its .ckt files and its syntax highlighting has not proved satisfactory. So I have done it for myself:

To make a difference between your local changes and the global changes of vim you should work in your home directory and create a local vim configuration dir:
$ mkdir ~/.vim
Vim has to recognize the GNUCap .ckt-files. These are almost compatible with the SPICE ones so the SPICE syntax highlighting file is a good start:
$ echo -e "\"Gnucap syntax highlighting \nau BufNewFile,BufRead *.ckt setf spice" >> ~/.vim/filetype.vim
Now you can test if that stuff works by viewing a *.ckt-file with vim:
vim /usr/share/doc/gnucap/examples/eq2-145.ckt
If there is no highlighting you should enable it:
$ echo "syntax enable" >> ~/.vimrc
Note: There is a difference between “syntax enable” and “syntax on”: enable respects all your local changes, on prefers the default settings.
One thing you see is that the comments are not highlighted. We will change this now by respecting the original spice syntax file:

$ mkdir ~/.vim/after
$ mkdir ~/.vim/after/syntax

In this new directory you create a file named spice.vim (vim ~/.vim/after/syntax/spice.vim):

1 " the first sign is a capital letter so this is a component
2 syn match spiceStatement "^\C[CDEFGHIJKLMQRSTUVWXY]"
3
4 "floating point value, with dot, optional exponent
5 syn match Identifier "\<[0-9]\+\.[0-9]*\(e[-+]\=[0-9]\+\)\=\(meg\=\|[afpnumkg]\)\=$"
6 "floating point value, starting with a dot, optional exponent
7 syn match Identifier "\.[0-9]\+\(e[-+]\=[0-9]\+\)\=\(meg\=\|[afpnumkg]\)\=$"
8 "integer value with optional exponent
9 syn match Identifier "\<[0-9]\+\(e[-+]\=[0-9]\+\)\=\(meg\=\|[afpnumkg]\)\=$"
10
11 " the first line is the name of the file - this line has to be the last to
12 " override all other rules
13 syn match PreProc "\%^.*"

Now all .ckt files will be displayed a little bit more coloreful. The chosen groups are vim default groups. I have chosen them almost randomly because the color is not relevant for me. :)

Keine Kommentare »

Noch keine Kommentare

RSS Feed für Kommentare zu diesem Artikel. | TrackBack URI

Hinterlasse einen Kommentar

XHTML ( You can use these tags):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

Kay Smarczewski


mein Blog

Seiten

Was beschäftigt mich gerade...

  • Alles in allem: Sensationeller und unvergesslicher Tag! #Leben 6 hrs ago
  • Im dritten Spiel gegen Möbius/Zielke etwas die Spannung verloren und deswegen im 3. Satz knapp unterlegen #Beachvolleyball #Leipzig 6 hrs ago
  • Auf dem Center Court gegen Becker/Drößler super gespielt und knapp verloren #Leipzig #Beachvolleyball 6 hrs ago
  • More updates...

Posting tweet...

Powered by Twitter Tools

Kalender mit Posts

Mai 2008
M D M D F S S
« Apr   Jun »
 1234
567891011
12131415161718
19202122232425
262728293031  

Schlagwörter

06 amd64 backup calculation cisco config connection console cron csv csv2latex debian diskussion dresden dresdner sc dsc english enlisch vim latex wiki wikipedia wikimedia snipmate snippet syntax entlassung extension Framework gerüchte gnuplot htw Informatik Informationssystemtechnik IST Java keyboard komma latex linux manager mode mysql5 oscommerce pear php4 php5 plesk Praktikum Studium suse TU typo3

Dieses Blog durchsuchen

© Kay Smarczewski – Powered by WordPress