Thursday, October 08, 2009

How to create Netem distribution tables

3 comments

The Netem and Dummynet emulators are widely used in networking research to achieve emulated network environments that can be used to evaluate new protocols and applications under controlled and repeateable conditions. In the case of Netem it is possible to use custom ditribution tables to better approximate the round-trip-time variations in the nework.

Unfortunately there is little information on how to generate this distribution tables based on real measured data. The only reference available is in the iproute2 source code itself and is a little confusing. After some reading and re-reading I think I finally got the magic formula and here I present it so others can benefit of my work.

First download the iproute2 source code:


git clone \
git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git


Then enter the netem subdirectory and compile the maketable and stats utilities:


cd iproute2/netem
gcc -lm -o maketable maketable.c
gcc -lm -o stats stats.c


Next you need to extract some delay statistics of the channel you want to emulate. Suppose you want to emulate the network between a server in Japan and a client PC in Chile. Then simply run a ping between both machines for some period of time. A whole day of ping data would be enough:


ping 192.168.4.111 > mydata.txt


The command above does a ping to the address 192.168.4.111 and stores the output to a file named mydata.txt. The file will contain the round-trip-times between the local machine and the machine with address 192.168.4.111 like shown below:


PING 192.168.4.111 (192.168.4.111) 56(84) bytes of data.
64 bytes from 192.168.4.111: icmp_seq=1 ttl=43 time=306 ms
64 bytes from 192.168.4.111: icmp_seq=2 ttl=43 time=273 ms
64 bytes from 192.168.4.111: icmp_seq=3 ttl=43 time=310 ms
64 bytes from 192.168.4.111: icmp_seq=4 ttl=43 time=300 ms
64 bytes from 192.168.4.111: icmp_seq=5 ttl=43 time=300 ms
64 bytes from 192.168.4.111: icmp_seq=6 ttl=43 time=304 ms
...


The more data you have the better so leave the ping running for some long period of time. Next we need to extract the round-trip-time data only:



cat mydata.txt | grep icmp_seq | cut -d'=' -f4 | cut -d' ' -f1 > myrtt.txt



The above command will extract all the round-trip-times from mydata.txt and put them in a single column in a file named myrtt.txt. Finally we can create a distribution table that Netem understands using the maketable utility:


./maketable myrtt.txt > mydist.dist


This will create a distribution table and store it in the file mydist.dist that must be copied in a special folder (/usr/lib/tc) so Netem can find it:


sudo cp mydist.dist /usr/lib/tc


Additionally we can obtain the mean and standard deviation of the round-trip-time using the stats utility:


./stats myrtt.txt
> mu = 296.636364
> sigma = 12.808378
> rho = -0.103472


This command gives use the mean (mu) the deviation (sigma) and the correlation (rho) of the round-trip-time. And at last we can now use Netem to emulate the channel's round-trip-time using the following command:



sudo tc qdisc add dev eth0 root netem delay 296.636364ms 12.808378ms distribution mydist



Note the the distribution name is the same as that of the file we copied inside the /usr/lib/tc folder but without the .dist extension. Now Netem will provide you with a channel that has similar round-trip-time characteristics as those of the real channel.

[get this widget]

Friday, June 12, 2009

Handling multiple encodings in Vim

1 comments

Most people edit, load and save files in a single character encoding (i.e. en_US.UTF-8) but for many this is not the case. For me I need to write documents and emails in japanese UTF-8 (ja_JP.UTF-8), Latex in EUC-JP (ja_JP.EUC-JP) and source code comments in Shift-JIS (ja_JP.SJIS).

To handle a certain character encoding there are three things you must consider:


  • Your editor character encoding

  • Your terminal character encoding

  • Your font character encoding support



In the prehistoric era editors and terminal could support a single character encoding so you needed a different pair for each encoding you needed. Believe me when I tell you this was not fun at all.

These days most editors and terminals support a large array of character encodings and a lot of free fonts are available that support all the character sets I need. Still it is necessary to reconfigure each part (editor/terminal) or create different profiles for each character encoding you needed to edit (i.e. link) for the editor and the console.

Today I took the time to understand how vim character encoding support works and I found that it has everything I need and a lot more. By carefully manipulating the the fenc, fencs, enc and tenc configuration parameters I can edit any file in any character encoding with little effort. Here are my .vimrc configuration parameters:


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"" Character encoding settings

"" By manipulating this variables it is possible to edit all files in one

"" encoding while using the terminal in a different encoding and writing/reading

"" the file in another encoding. Here we set all three variables to UTF-8.

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""



" Default file encoding for new files

setglobal fenc=utf-8



" Auto detect file encoding when opening a file. To check what file encoding was

" selected run ":set fenc" and if you know the auto detection failed and want to

" force another one run ":edit ++enc=<your_enc>".

set fencs=utf-8,euc-jp,sjis



" Internal encoding used by vim buffers, help and commands

set enc=utf-8



" Terminal encoding used for input and terminal display

" Make sure your terminal is configured with the same encoding.

set tenc=utf-8





  • tenc:

    This is the character encoding used to display and input text to the terminal. I configure my terminal (Konsole) always in UTF-8 and as far as I know my input method for Japanese (scim/anthy) is also UTF-8 so to avoid visual/input problems I leave this in UTF-8.

  • enc:

    The encoding used internally by vim buffers, help and commands. This does not need to be the same as tenc as vim will convert from one encoding to the other if they differ. This way you can use your native language encoding in your terminal and input method and let vim handle everything internally using UTF-8.


  • fenc:

    Is the character encoding used for reading/writing files. Again this can differ from enc and tenc because vim will convert between them if they differ. This way you can have your terminal configured with your native language (i.e. Japanese, Russian, Chinese...), let vim work internally in UTF-8 and finally save your files in any coding you want by setting fenc.


  • fencs:

    This is used by vim to try to auto detect the character encoding when opening an already existing file. The order in which you put the options is important so read the help ":h fencs" to learn how to set this correctly. For example if I put euc-jp first in the list all my English documents will be detected as euc-jp instead of utf-8 because all English characters are a subset of euc-jp, the same goes for latin1 and cp1250 encodings so make sure to put these at the end of the list. If the auto detection fails and your document is not displayed correctly you can always reload it forcing an encoding using ":edit ++enc=euc-jp" of course replace euc-jp with your desired encoding.


In my example above I set everything to UTF-8 that is recommended because converting from other encodings may cause loss of information. The only parameter I change is fenc when I need edit/save a file in a different encoding.

For example if I want to create a new file in euc-jp encoding:


- Open new file as normal using vim<
- Set file encoding using :set fenc=euc-jp
- Edit/Save as much as you like and rest assured that your file is euc-jp.



To edit an existing file simply open it and let vim auto detect the encoding using the options available in fencs. To check what encoding was set by vim you can use the command ":set fenc" and it will display the auto detected encoding. If it is not the correct one you can force the encoding by reloading the file using the command ":edit ++enc=euc-jp" replacing "euc-jp" with the encoding you desire.

[get this widget]

Vim tips for Latex editing

0 comments

Simple Latex Makefile



With this simple Makefile you can compile your latex projects from within vim and use the quickfix window in case of errors to traverse and fix them one by one.



#

# This makefile generates a PDF of the MAINTEX file.

# The output can be found inside the build subdirectory.

#

# Makefile based on  http://www.wlug.org.nz/LatexMakefiles

#

#

# This makefile has been tested in Kubuntu 9.04

#

# Prerequisites:

#

# sudo aptitude install ptex-bin ptex-base okumura-clsfiles ptex-jisfonts \

#     xdvik-ja dvipsk-ja dvi2ps gv jbibtex-bin jmpost mendexk okumura-clsfiles \

#     vfdata-morisawa5 dvi2ps-fontdesc-morisawa5 texlive-latex-extra latexmk \

#     dvipng xpdf gs-cjk-resource vfdata-morisawa5 dvi2ps-fontdesc-morisawa5 \

#     cmap-adobe-japan1 cmap-adobe-japan2 cmap-adobe-cns1 cmap-adobe-gb1

# sudo jisftconfig add

#

# When writing Japanese make sure your editor is saving the tex files

# in euc-jp encoding. In VIM this can be accomplished by setting the fenc

# variable:

#

#  - Open file as normal using vim <filename>

#  - Type  :edit ++enc=euc-jp

#  - Type  :set fenc=euc-jp

#  - Type  :set enc=utf-8



## TODO Add rule to convert images

## TODO Add makeindex to create .toc files



###########################################################################

## Put here the file name of the main tex file.

MAINTEX      = main



############################################################################

## Change the followin only if you know what you are doing

LATEXCMD     = platex     # [latex | platex]

BIBCMD       = jbibtex    # [bibtex | jbibtex]

DVIPDFCMD    = dvipdf     # [dvipdf | dvipdfm | dvipdfmx]

PDFVIEWER    = xpdf       # [okular | xpdf | evince ]

DVIVIEWER    = xdvi-ja    # [xdvi | xdvi-ja | kdvi ]



## No need to change anything below this line

TEXFILES     = $(wildcard *.tex)

TEXINPUTS=:$(PWD)//:    # Path to search for .tex, .cls and .sty files

BSTINPUTS=:$(PWD)//:    # Path to search for .bst files

BIBINPUTS=:$(PWD)//:    # Path to search for .bib files

TEXMFOUTPUT=$(PWD)/build  # Output dir for bibtex and jbibtex

LATEXOPTS= -output-directory=build -file-line-error -interaction=nonstopmode



export TEXFILES TEXINPUTS BSTINPUTS BIBINPUTS TEXMFOUPUT



.PHONY: all wordcount charcount pdf dvi



all: build/$(MAINTEX).pdf



build :

        @echo "Creating build directory"

        @mkdir build



build/$(MAINTEX).aux: $(MAINTEX).tex $(TEXFILES) build

        $(LATEXCMD) $(LATEXOPTS) $(MAINTEX) 



build/$(MAINTEX).bbl: build/$(MAINTEX).aux

        $(BIBCMD) build/$(MAINTEX)



build/$(MAINTEX).dvi: build/$(MAINTEX).bbl

        $(LATEXCMD) $(LATEXOPTS) $(MAINTEX) 

        $(LATEXCMD) $(LATEXOPTS) $(MAINTEX) 



build/$(MAINTEX).pdf: build/$(MAINTEX).dvi

        $(DVIPDFCMD) build/$(MAINTEX).dvi build/$(MAINTEX).pdf



dvi: build/$(MAINTEX).dvi

        $(DVIVIEWER) build/$(MAINTEX).dvi



pdf: build/$(MAINTEX).pdf

        $(PDFVIEWER) build/$(MAINTEX).pdf



# Word counting can be done in VIM usng Ctrl-g g but this command also includes

# latex commands. This make rule strips the latex and counts what is left

wordcount:

        @echo Approximate word count: `grep -v '^\\\\' $(TEXFILES)|grep -v '^%'|wc -w`



charcount:

        @echo Approximate char count: `grep -v '^\\\\' $(TEXFILES)|grep -v '^%'|wc -c`






Put all your tex files, images, sty, cls, bib, bst files inside a directory with any subfolder tree structure you like. This Makefile sets some environment variables that allow it to find all these files as long as they are below the current directory tree.

Make sure your main tex file is called main.tex or if you prefer another one replace the MAINTEX variable in the Makefile. Take note that it has no extension!.

Also note that this Makefile is to compile Japanese EUC-JP tex files (IEICE Trans). If you do not need Japanese replace platex with simple latex and jbibtex with bibtex.

All output files generated by latex/platex, bibtex/jbibtex are stored inside a build subdirectory.

Now in your .vimrc you can add the following parameter to compile your latex project:



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Working with Makefiles

"

" Press F5 to compile and open the error window if there

" are errors. If there are errors you can use :cn and :cN to

" jump foward and backward thru the error list. Press :ccl to

" close the error list or F5 again to recompile

map <F5> <ESC>:make<CR><ESC>:botright cwindow<CR> " Compile and open quick fix list

map <F6> <ESC>:cN<CR>                             " Jump to prev error/warn

map <F7> <ESC>:cn<CR>                             " Jump to next error/warn






Now when editing you latex files press <F5> to compile them and if errors occur you will be presented with a quickfix window where you can use <F6> and <F7> to quickly jump to the previous and next error message.

Additionally this Makefile also has a few useful commands you can invoke from within vim:



  • :!make pdf to display the pdf file using xpdf or if you prefer a different viewer replace the PDFVIEWER variable in the Makefile.


  • :!make dvi to display the dvi file using xdvi or if you prefer a different viewer replace the DVIVIEWER variable in the Makefile.


  • :!make wordcount to display the number of words in all the tex documents. In vim you can also use g<ctrl-g> in normal mode but this also counts latex commands.


  • :!make charcount same as wordcount but for characters instead of words.



Latex with Vim TagList plugin





We can enable TagList to display important keywords like section, labels and references for easy navigation (link).

First create a ~/.ctags file that contains the following:


--langdef=tex
--langmap=tex:.tex
--regex-tex=/\\subsubsection[ \t]*\*?\{[ \t]*([^}]*)\}/- \1/s,subsubsection/
--regex-tex=/\\subsection[ \t]*\*?\{[ \t]*([^}]*)\}/+\1/s,subsection/
--regex-tex=/\\section[ \t]*\*?\{[ \t]*([^}]*)\}/\1/s,section/
--regex-tex=/\\chapter[ \t]*\*?\{[ \t]*([^}]*)\}/\1/c,chapter/
--regex-tex=/\\label[ \t]*\*?\{[ \t]*([^}]*)\}/\1/l,label/
--regex-tex=/\\ref[ \t]*\*?\{[ \t]*([^}]*)\}/\1/r,ref/


Then modify the taflist.vim file and add a new language. To do this search for "yacc language" and add these line before it:


" tex language
let s:tlist_def_tex_settings = 'tex;s:section;c:chapter;l:label;r:ref'

" yacc language


Now when you open the taglist window you will get a nice list of section, subsections, chapters, references, labels, etc... that you can navigate and use to jump quickly to each of them.

If you do not have the taglist plugin installed you can follow my instructions here.

Reference autocompletion





If you write your labels as \label{fig:something}, then put this in your ~/.vimrc file:



set iskeyword+=:           " type /ref{fig: and prec <C-n> to autocomplete references



With this now you can type \ref{fig: and press to get a list of labels you can cycle as shown in the image above.


Spell checking



This is not only for latex files. Simply put the following in your ~/.vimrc file to enable automatic spell checking. Learn how to use the spell checker to correct, add and/or ignore words.



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Enable spell checking in latex, bib and txt files

" Commands:

"            [s      ->  jump to next bad word

"            ]s      ->  jump to prev bad word

"            z=      ->  suggest word

"            zg      ->  mark word as good (add to dictionary)

"            zw      ->  mark word as bad  (remove from dictionary)

"            :h spell -> get more details about spelling

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

au BufRead,BufNewFile *.txt,*.tex,*.bib  setlocal spell spelllang=en_us






[get this widget]

Wednesday, November 12, 2008

Mounting Windows Shares Using CIFS on Ubuntu

0 comments

So you have a cool Buffalo LinkStation Pro Duo or a Windows machine with some shared folders you want to access from your super Linux machine. No problems we have CIFS to the rescue!!

These instructions were tested in Kubuntu 8.10 (Ibex) but shall work with previous versions and future versions of Kubuntu and/or Ubuntu. Also I assume you want the share to be available to all users in the system so you need root access (i.e. sudo).

First install smbfs package:


sudo aptitude install smbfs


Create a directory were you want to mount the shared folder, any place is ok:


sudo mkdir /media/share


If the share requires username and password to access create a password file in you home directory:


sudo echo -e "username=my_username\npassword=my_password" > /root/.share_pass
sudo chown root:root /root
sudo chmod 700 /root/.share_pass


Replace "my_username" and "my_password" with the corresponding user and pass to access the remote share.

Finally create an entry in the "/etc/fstab" file to mount the shared folder in the desired mount point:


//ip-address/share /media/share credentials=/root/.share_pass,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0


Here you must replace //ip-address/share with the ip address of the machine with the shared folder and the complete path to the respective folder.

Finally mount all partitions:


sudo mount -a


Now you must be able to access the shared folder at the remote machine by accessing the /media/share directory.


References



http://ubuntuforums.org/showthread.php?t=288534

[get this widget]

Sunday, October 19, 2008

NVidia InitialPixmapPlacement=2 really improves KDE speed

0 comments



Some people say KDE4 rendering speed is slow when using Nvidia cards. I never felt this so I never bothered in applying the proposed solutions. Using firefox (note: this test does not run in konqueror) simply access the penroseTitling test page and run both tests. My first tests are in the image above and as you can see not bad as I have read in the Internet that for some people the Canvas test can take up to 30 seconds while it took 3 seconds on my machine.

Anyway I tried one of the solutions that is simply running this command in the konsole:


nvidia-settings -a InitialPixmapPlacement=2 -a GlyphCache=1


And here are the new times:



Wow this is a real improvement so now I have a kde startup script that calls this command when KDE starts:


# ~/.kde4/Autostart/nvidia.sh
!#/bin/bash
nvidia-settings -a InitialPixmapPlacement=2 -a GlyphCache=1 &


Resources:
http://movingparts.net/2008/10/03/kde-42-trunk-now-rocking-on-my-thinkpad-t61/
http://techbase.kde.org/User:Lemma/KDE4-NVIDIA

[get this widget]

Thursday, October 09, 2008

Use vimdiff as Subversion diff command

2 comments



First create a script svbdiff inside the ~/.vim/scripts/ directory that contains the following


#!/bin/bash
shift 5;/usr/bin/vimdiff -f "$@"


and make it executable:


chmod +x ~/.vim/scripts/svndiff


Then create an alias in your ~/.bashrc file like:


alias svndiff="svn diff --diff-cmd ~/.vim/scripts/svndiff"


Now you can go to any Subversion repository and display file differences with


svndiff h264.c


The screenshot above shows the diff output of the h264.c of libavcodec. Make sure you have a color scheme that highlights the file differences. The screenshot above uses the inkpot color scheme.

[get this widget]

My Vim Tips

0 comments

List of my Vim Tips



[get this widget]

Open new files as tabs in current Vim Console

4 comments

When programming I like to have a single Vim editor open with all my files as tabs. Until now I was using the ":tabnew" command to open files in the current Vim window as I knew no other way.

Some research led me to the --remote-tab switch that allows to open files as tabs in currently open Vim processes but it seemed to work only with the graphical interface (gvim) and not with the console (vim). But as I made some tests I found this can work with the vim in console mode and more over can be nicely integrated with my favorite file managers (Konqueror/Dolphin).

All I needed to do was configure my bash so it will always start vim in server mode if it is not already and to always use the --remote-tab switch when opening files. To do this I simply added these functions to my ~/.bashrc file:


function v {

   if [ "$#" -eq "0" ]; then

      /usr/bin/vim --servername VIMLOCAL

   else

      if echo "$*" | grep -q -- "--servername" ; then

        # echo "Command already has --servername use it"

        /usr/bin/vim $*

      else

          #echo "Use default VIM server VIMLOCAL"

          /usr/bin/vim --servername VIMLOCAL --remote-tab-silent $*

      fi

   fi

}



function gv {

   if [ "$#" -eq "0" ]; then

      /usr/bin/gvim --servername GVIMLOCAL

   else

      if echo "$*" | grep -q -- "--servername" ; then

        # echo "Command already has --servername use it"

        /usr/bin/gvim $*

      else

          #echo "Use default VIM server VIMLOCAL"

          /usr/bin/gvim --servername GVIMLOCAL --remote-tab-silent $*

      fi

   fi

}



alias vi=v

alias vim=v

alias gvim=gv





With these functions loaded (i.e. source ~/.bashrc) the first time you execute vim/gvim it will start a new process in server mode.


# this command will open vim in the current console
# and display first_file.txt for editing.

vim first_file.txt


The second and all subsequent times you execute vim/gvim the files you set as parameters will be opened as tabs in the already opened vim/gvim instance.


# This command in other console will open the files
# second_file.txt and third_file.txt as tabs in the
# other console with first_file.txt open

vim second_file.txt third_file.txt


The above examples work also with gvim instead of vim. The only drawback is that now it is difficult to open files in a separate console. The best solution I found is to call vim with a different server name:


# This command will create a new instance of vim in the current console window
# and display the other_file.txt file for editing.

vim --servername OTHERNAME other_file.txt


If you prefer not to use tabs and like files to be opened as buffers inside a current running Vim instance then simply replace "--remote-tab-silent" with "--remote-silent" in the above scripts.

[get this widget]

Make Vim and Ctag play nice together

1 comments

CTags and Vim are a killer combination for developing all kinds of programs in all kinds of languages. These tools are very flexible by themselves and combined we have so many options on how to use them together that it becomes very difficult to do efficiently.

For example you can configure Vim to auto generate ctags based on programming language and to search for tags files in every imaginable part of your hard disk. So how should one decide were to put the ctag files, how to generate them and how to access them?.

Here I talk about how I personally handle ctag files and how I configure vim to auto generate and search them.

Pre requisites

The following instructions were tested on a Linux machine installed using Kubuntu 8.10, 9.04 and 9.10. The first step is of course to make sure you have installed Vim and exuberant-ctags in you machine. For instruction on how to install Vim with minimal configuration refer to this link. To install exuberant-ctags simply execute the following command in a konsole window:


sudo aptitude install exuberant-ctags


Generate system wide ctags

I usually generate ctag files for the languages and libraries I use in my projects and save them inside my ~/.vim directory. This way I can easily jump to these library definitions.

To do so create some folders to store the ctag files:


mkdir -p ~/.vim/tags/linux
mkdir -p ~/.vim/tags/local


Then generate ctag files for each library and language you intent to use:


# Create system tags for linux kernel. This will allow you to jump 
# to the linux header files:

sudo aptitude install linux-headers-`uname -r`
ctags -R -f ~/.vim/tags/linux/ctags /usr/src/linux-headers-`uname -r`

# Create system tags for ruby

ctags -R -f ~/.vim/tags/linux/rbtags /usr/lib/ruby

# Create system tags for Java

# For the java tags to work you need to install java source package.
# In Kubuntu/Ubuntu follow these instructions:

sudo aptitude install sun-java6-source
sudo mkdir -p /usr/lib/jvm/java-6-sun/src
sudo unzip -d /usr/lib/jvm/java-6-sun/ /usr/lib/jvm/java-6-sun/src.zip
ctags -R -f ~/.vim/tags/linux/javatags /usr/lib/jvm/java-6-sun/src

# You may create additional ctag files for other libraries like QT,
# SDL, etc.



Configure Vim to generate/update your local ctag files

Creating ctag files for libraries can be done when a new version is available or when you modify/replace it. On the other hand your own projects may change in a daily or even hour basis so you need to update your ctag files all the time in order to use them during your project development.

To tackle this I create some local ctag files, one for each programming language I use, and tell Vim to update them every time a file I edit changes. This is very simple to do by adding the following lines to the vim configuration file (i.e. ~/.vimrc):



let _ctag_ = "ctags -a -f ~/.vim/tags/local/ctags --extra=+q "
au BufWritePost *.cpp,*.h,*.c,*.rl,*.def call system(_ctag_ . expand("%:p"))

let _rbtag_ = "ctags -a -f ~/.vim/tags/local/rbtags --extra=+q "
au BufWritePost *.rb call system(_rbtag_ . expand("%:p"))

let _pytag_ = "ctags -a -f ~/.vim/tags/local/pytags --extra=+q "
au BufWritePost *.py call system(_pytag_ . expand("%:p"))

let _jtag_ = "ctags -a -f ~/.vim/tags/local/javatags --extra=+q "
au BufWritePost *.java call system(_jtag_ . expand("%:p"))



Finally we must tell vim where to look for these tags by adding the following to the ~/.vimrc configuration file:

au BufRead,BufNewFile *.rb setlocal tags+=~/.vim/tags/local/rbtags,~/.vim/tags/linux/rbtags
au BufRead,BufNewFile *.cpp,*.h,*.c setlocal tags+=~/.vim/tags/local/ctags,~/.vim/tags/linux/ctags
au BufRead,BufNewFile *.rl,*.def setlocal tags+=~/.vim/tags/local/ctags,~/.vim/tags/linux/ctags
au BufRead,BufNewFile *.py setlocal tags+=~/.vim/tags/local/pytags,~/.vim/tags/linux/pytags
au BufRead,BufNewFile *.java setlocal tags+=~/.vim/tags/local/javatags,~/.vim/tags/linux/javatags

set tags=./.tags;${HOME}


Note that we use setlocal instead of simply set so the tag files are added to the current edit buffer only. This is done so we do not add all tag files to every file as we do not need for example the ruby tag file when editing a python script.

The last set command is to tell vim to search for ".tags" files inside the current folder recursively up to your HOME directory. We do not want vim tracking all the tag files up to ROOT do we?

Additionally I recommend you to use the TagList plugin that will provide a nice list with all your tags so you can easily jump from tag to tag.

Here is the complete vim configuration. Simply copy paste this in your own .vimrc file and follow the instructions in the comments.



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"" Make vim work nice with exuberant ctags

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Install exuberant-ctags in your system

"    - i.e. for Kubuntu:  sudo aptitude install exuberant-ctags

"



" Vim Tip #1299 - Update local tags when files are saved

"

"    Create a folder to store the tag files: mkdir -p ~/.vim/tags/local



let _ctag_ = "ctags -a -f ~/.vim/tags/local/ctags --extra=+q "

au BufWritePost *.cpp,*.h,*.c,*.rl,*.def call system(_ctag_ . expand("%:p"))



let _rbtag_ = "ctags -a -f ~/.vim/tags/local/rbtags --extra=+q "

au BufWritePost *.rb call system(_rbtag_ . expand("%:p"))



let _pytag_ = "ctags -a -f ~/.vim/tags/local/pytags --extra=+q "

au BufWritePost *.py call system(_pytag_ . expand("%:p"))



let _jtag_ = "ctags -a -f ~/.vim/tags/local/javatags --extra=+q "

au BufWritePost *.java call system(_jtag_ . expand("%:p"))



" Vim Tip #804 - Generate System Tags for your favorite languages

"

"    Create a folder to store the system tag files: mkdir -p ~/.vim/tags/linux

"

"    Create system tags for linux kernel.

"

"       sudo aptitude install linux-headers-`uname -r`

"       ctags -R -f ~/.vim/tags/linux/ctags /usr/src/linux-headers-`uname -r`

"

"    Create system tags for ruby

"

"       ctags -R -f ~/.vim/tags/linux/rbtags /usr/lib/ruby

"

"    Create system tags for Java

"

"       sudo aptitude install sun-java6-source

"       cd /usr/lib/jvm/java-6-sun

"       sudo mkdir src

"       sudo unzip -d src src.zip

"       ctags -R -f ~/.vim/tags/linux/javatags /usr/lib/jvm/java-6-sun/src

"

"     Finally configure vim to read these tags depending of the buffer filetype.

"     Also you may add other system tags for perl and/or python

"

au BufRead,BufNewFile *.rb setlocal tags+=~/.vim/tags/local/rbtags,~/.vim/tags/linux/rbtags

au BufRead,BufNewFile *.cpp,*.h,*.c setlocal tags+=~/.vim/tags/local/ctags,~/.vim/tags/linux/ctags

au BufRead,BufNewFile *.rl,*.def setlocal tags+=~/.vim/tags/local/ctags,~/.vim/tags/linux/ctags

au BufRead,BufNewFile *.py setlocal tags+=~/.vim/tags/local/pytags,~/.vim/tags/linux/pytags

au BufRead,BufNewFile *.java setlocal tags+=~/.vim/tags/local/javatags,~/.vim/tags/linux/javatags



" Vim Tip #94 - Set tags search path recursive up to $HOME

set tags=./.tags;${HOME}



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"" Tag list features

"" Install the all powerfull taglist plugin so you can browse using the ctags

""

""   Get taglist_45.zip from http://vim-taglist.sourceforge.net/

""   Uncompress to your vim directory:  unzip -d ~/.vim taglist_45.zip

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let Tlist_Auto_Open=1

let Tlist_Auto_Update=1

let Tlist_Use_Horiz_Window = 0

"let Tlist_Inc_Winwidth=0

"let Tlist_Show_One_File=1

let Tlist_Exist_OnlyWindow=1

let Tlist_Use_Right_Window = 1

let Tlist_Sort_Type="name"

let Tlist_Display_Prototype=0

let Tlist_Compact_Format=1 " Compact?

let Tlist_GainFocus_On_ToggleOpen=1

let Tlist_Display_Tag_Scope=1

let Tlist_Close_On_Select=1

let Tlist_Enable_Fold_Column=1

"let TList_WinWidth=25




[get this widget]

Wednesday, October 08, 2008

Basic .vimrc file

3 comments



My first Vim configuration files: .vimrc, plugins, color schemes, etc were very small and modest. It's been eight years since I started using Vim and these configuration files have morphed, evolved, grown and recently shrink in too many ways, more than I can remember, and every time I check www.vim.org I find new ways I would like my Vim to evolve even further.

Here is the simplest version of my .vimrc file with no ctags or desktop integration as these topics require a separate post to explain. Most of the options here can be understood directly from Vim help files and by the comments in the file itself.

If you would like to use this file make sure to copy it in your home directory and read the comments as to get full functionality.

For comparison see the default install and my older configuration screenshot at the end of the post and compare it with my current configuration screenshot at the top of this post.



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"" General Vim Settings

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"   In Kubuntu/Ubuntu make sure you have a complete vim install

"   i.e.  sudo aptitude install vim-ruby vim-scripts vim-common

"



" Disable compatibility with vi

set nocompatible



" Use the Unix file format

set fileformats=unix,dos



" Display line number in front of each line in the left margin.

set number



" I keep my own backups and all those files ending in '~' are

" anoying.

set nobackup



" Display commands in the bottom right corner as they are typed.

set showcmd



" Smoother redraws

set ttyfast



" Avoid vim complains about not written file when jumping

" between buffers using ctags.

set autowrite



" Vim Tip #1160 - Auto Save files when focus is lost.

au FocusLost * :wa



" Vim Tip #1279 - Highlight current line in Insert Mode

autocmd InsertLeave * se nocul

autocmd InsertEnter * se cul



" Enable syntax highlighting with 256 color support so we

" can use nicer color schemes. For more information and to

" get some nice color schemes check:

"   http://www.frexx.de/xterm-256-notes/

" Tested with Konsole-2.1 and yakuake 2.9.4

set t_Co=256

syntax on



" Set this background depending on your console and color scheme.

set background=light

"set background=dark



" My favorite color schemes. You must download the color themes

" and put them inside the color folder of your vim installation.

"colors default     " Good fro transparent consoles

"colors zenburn     " Vim Tip #415

colors 256_asu1dark " http://www.frexx.de/xterm-256-notes/

"colors pyte        " Vim Tip #1492



" If in diff mode (vimdiff) use the inkpot color scheme

" that better highlights file differences

if &diff

  colors inkpot    " Vim Tip #1143

endif



" Additional filetypes

au BufRead,BufNewFile sconstruct setlocal filetype=python

au BufRead,BufNewFile *.rl       setlocal filetype=ragel

au BufRead,BufNewFile *.rb       setlocal filetype=ruby



" Additional Syntax Files. The ragel.vim file can be downloaded

" from Ragel's home page http://www.complang.org/ragel/.

au! Syntax ragel source ragel.vim



" Set path to search (i.e. gf) files recursively

set path=/usr/include,/usr/local/include,**;$HOME



" Vim Tip #1274 - Highlight trailing whitespace characters

set list

set listchars=tab:->,trail:·



" Number of spaces used for (auto)indenting

"set shiftwidth=2



" Number of spaces to insert for a tab

"set softtabstop=2

set tabstop=2



" Insert spaces when the tab key is pressed

" If you want a real tab use "ctrl-v, tab" in insert mode. This

" is usefull for Makefiles that require real tabs to work.

set expandtab



" Word wrap with line breaks if they are longer than 80 characters

" long. If you prefer to wrap lines visually only use the wrap and

" lbr commands below instead. If you have a document that has lines

" longer than 80 characters you can use "gq}" to format it as a

" paragraph. This is more easier format for navigating the text.

set textwidth=80

set formatoptions=tcq



" Vim Tip #989: Word wrap without line breaks

"set wrap

"set lbr



" Enable specific indenting

set autoindent

set smartindent



" Enable code folding

set foldmethod=syntax



" Show briefly matching bracket when closing it.

set showmatch



" Show cursor position

set ruler



" Additonal key mappings

map <F12> <ESC>ggVGg?                             " ROT13 fun



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"" Mini buffer explorer features

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

let g:miniBufExplSplitBelow=0

let g:miniBufExplSplitToEdge = 0

let g:miniBufExplVSplit = 20

let g:miniBufExplMapCTabSwitchBufs = 1

let g:miniBufExplUseSingleClick = 1

let g:miniBufExplorerMoreThanOne=0 

let g:miniBufExplModSelTarget = 1



" Map Tab and Shift-Tab for buffer navigation

" Note that S-TAB does not work in certain consoles (i.e. KDE Konsole)

map <TAB> <ESC><C-TAB>

map <S-TAB> <ESC><C-S-TAB>



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"" Improve VIM autocomplete features

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Enable search as you type:

set incsearch



"improve autocomplete menu color

highlight Pmenu ctermbg=238 gui=bold



" http://www.cuberick.com/2008/10/ruby-autocomplete-in-vim.html

autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete

autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1

autocmd FileType ruby,eruby let g:rubycomplete_rails = 1

autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Vim tip #90 Enable VCS integration in vim

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"  Get vcscommand.zip from http://www.vim.org/scripts/script.php?script_id=90

"  Uncompress to your vim directory:  unzip -d ~/.vim vcscommand.zip

"

"  Now when editing a file that is under revision control (SVN, CVS, Git,...)

"  we can access the versioning commands:

"

"  VCSAdd

"  VCSAnnotate

"  VCSCommit

"  VCSDelete

"  VCSDiff

"  VCSGotoOriginal

"  VCSGotoOriginal!

"  VCSInfo

"  VCSLog

"  VCSLock

"  VCSReview

"  VCSStatus

"  VCSUpdate

"  VCSUnlock

"  VCSVimDiff



" Map F4 to VimDiff to check differences

map <F4> <ESC>:VCSVimDiff<CR>



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Latex Configuration

" http://vim-latex.sourceforge.net/documentation/latex-suite/recommended-settings.html

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

au BufRead,BufNewFile *.cls      setlocal filetype=tex

"let g:tex_flavor='latex'   " loads latexsuite with empty tex files.

set iskeyword+=:           " type /ref{fig: and press <C-n> to autocomplete references



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Working with Makefiles

"

" Press F5 to compile and open the error window if there

" are errors. If there are errors you can use :cn and :cN to

" jump foward and backward thru the error list. Press :ccl to

" close the error list or F5 again to recompile

map <F5> <ESC>:make<CR><ESC>:botright cwindow<CR> " Compile and open quick fix list

map <F6> <ESC>:cN<CR>                             " Jump to prev error/warn

map <F7> <ESC>:cn<CR>                             " Jump to next error/warn



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Enable spell checking in latex, bib and txt files

" Commands:

"            [s      ->  jump to next bad word

"            ]s      ->  jump to prev bad word

"            z=      ->  suggest word

"            zg      ->  mark word as good (add to dictionary)

"            zw      ->  mark word as bad  (remove from dictionary)

"            :h spell -> get more details about spelling

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

au BufRead,BufNewFile *.txt,*.tex,*.bib  setlocal spell spelllang=en_us



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Other Good Vim tips not used here

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Vim Tip #64   - Set working dir to the file you are editing

"                 Why not used: Makes difficult the management of sessions and

"                   makefiles.

" Vim Tip #305  - List of editing vim tips

"                 Why not used: I can remember all the commands I use.

" Vim Tip #1203 - mapping to set up vtreeexplorer and taglist in left window

"                 Why not used: I use MiniBufExpl instead of vtreeexplorer

" Vim Tip #1318 - An attempt to emulate TextMate's snippet expansion

"                 Why not used: I am unable to get this working correctly.

" Vim Tip #???? - Force gf to open in new tabs  

"                 Command: nnoremap gf <C-W>gf

"                 Why not used: I use MiniBufExpl so no more tabs for me.

" Vim Tip #565  - Never see ^M and pesky trailing spaces again

"                 Command: autocmd BufRead * silent! %s/[\r \t]\+$//

"                 Why not used: Not a good idea when working with others source

"                  code. All the automatically deleted chars will be seen as

"                  changes in the diff files making it difficult to review the

"                  changes. Never use this if you plan to submit patches to ffmpeg

"                  or the Linux kernel or they will spam filter you forever!






[get this widget]

Thursday, September 25, 2008

Canon Satera LBP5910 Linux Driver

0 comments

If you have a Canon printer based on the LIPSLX driver (i.e. LBP family) then you are lucky because Canon provides the linux drivers for these printers.

Simply go to this page Canon Linux Driver check for the supported printers and the respective drivers. For my case I have the LBP5910F printer that is supported by the LIPS LX Printer Driver so I enter this page and download the two corresponding .deb packages for Ubuntu/Debian. If you use Redhat or any other distribution that uses RPMs then download the corresponding RPMs.

To install in Ubuntu/Debian:


sudo dpkg -i cndrvcups-common_1.70-1_i386.deb
sudo dpkg -i cndrvcups-lipslx_1.70-1_i386.deb
sudo /etc/init.d/cupsys restart


Now enter CUPS configuration page (i.e. http://localhost:631) and follow the steps. In my case the printer was already listed in the select box of printers with IP address and everithing. In Make/Manufacturer select Canon and finally in Model/Driver select the corresponding driver:



And that is all now you can try to print a test page.

[get this widget]