Thursday, December 08, 2011

Monday, November 29, 2010

Vim syntax higlight

To enable vim highlight user file type two things should be done:
  1. Write a ~/.vim/syntax/mytype.vim file with the description of the syntax highlighting rules.
  2. New file type ('mytype') is detected by adding its description into: ~/.vim/filetype.vim:
Example of description added to filetype.vim:
" VHDL
au BufNewFile,BufRead *.hdl,*.vhd,*.vhdl,*.vbe,*.vst setf vhdl
au BufNewFile,BufRead *.vhdl_[0-9]* call s:StarSetf('vhdl')

If syntax highlighting is not enabled by default, it can be enabled with: :set syntax=mytype

Monday, September 07, 2009

File sed search&replace

cat file.txt | sed -e '/foo/s//bar/g' > file.txt.TMP
mv file.txt.TMP file.txt

Friday, November 28, 2008

Find matching bracket in Vim

Just position cursor on a bracket and press % to go to the matching bracket!

Friday, November 14, 2008

Linux shell I/O redirecting

./my_script > file <-- Redirect standard output
./my_script 2> file <-- Redirect error output
./my_script &> file <-- Redirect all output
./my_script > file 2>&1 <-- Combined error and standard output

Friday, July 11, 2008

gnuplot + PlotDrop - plotting the data for high quality IEEE publications

gnuplot is a command-driven interactive function and data plotting program. PlotDrop is its simple and user friendly frontend. PlotDrop can be used with latex/pdflatex for generatating high quality figures for IEEE publications, theses, etc. Beside the limited number of gnuplot commands that are available through the GUI, PlotDrop enables specifying arbitrary commands through the Extra tab (command line style). The following gnuplot commands are more or less what I use when generating figures for IEEE publications:

  • set terminal postscript eps enhanced solid monochrome "NimbusSanL-Regu" fontfile "/usr/share/texmf-texlive/fonts/type1/urw/helvetic/uhvr8a.pfb"
1. enhanced flag enables enhanced text features (subscript/superscript)
2. solid flag makes all the lines non-dashed
3. monochrome flag makes all the lines black
4. "NimbusSanL-Regu" fontfile "/usr/share/texmf-texlive/fonts/type1/urw/helvetic/uhvr8a.pfb" - construct sets the default font to NimbusSanL-Regu instead of Helvetica and enables font embedding in the pdf (useful for IEEE papers produced with latex/pdflatex).
  • set size 0.75,0.75 - Scales the graph and not the fonts, so the fonts are bigger at the output.
  • set key bottom right - Puts the "legend" at the bottom right corner. Valid flags are: top, center, bottom, right, left, above, below, outside and inside. Also, you can specify absolute coordinates of the top-right box corner within the plot coordinate system, as follows: set key at 4.2,0.2.
  • set key spacing 2 - Increases the vertical spacing between labels in the "legend".
  • set key box - Draws the box around the "legend".
  • set key width 1 - Increases the key box width by the width of 1 character.
  • set pointsize 1.5 - Sets the point (marker) size at 1.5 (default is 1).
  • set bar 1.5 - Sets the bar size at 1.5.
  • set ytics nomirror - Remove tics on the right (vertical) border line.
  • set xtics nomirror - Remove tics on the top (horizontal) border line.
  • set tics out - X and Y tics point outside instead of inside of the axes.
  • set title font "NimbusSanL-Regu,20"
  • set ylabel font "NimbusSanL-Regu,20"
  • set xlabel font "NimbusSanL-Regu,20"
  • set label font "NimbusSanL-Regu,20"
The previous four commands set title, y-axis and x-axis label and other labels fonts to NimbusSanL-Regu, size 20.

With this setup you can generate very good figures in ps/eps/fig/latex/etc. formats (Plot->Plot to file). To import figures in pdflatex you have to convert ps to pdf. For this conversion use epstopdf and not ps2pdf!