Category Archives: Tips & Tricks

Configuring ctags for Python and Vim

Exuberant ctags is a cool, language-agnostic tool for creating tag files for your source code. Nice editors such as Vim, could use these tag files to implement the much needed 'jump to definition' feature.

Ctags is awesome, it supports Python, and is supported by Vim. It seems that the world is perfect and there's no reason to write a post about configuring it. Well... almost.

ctags has a little downside when using Python: it recognizes import lines as a definition, at least as of ctags v5.8. No need to explain why it's annoying in most cases. After 2 years of suffering, I've found it's possible to overcome this simply by adding the --python-kinds=-i option to the command line, or better: to ~/.ctags.

And just to make it complete, a quick cookbook style for setting everything up and using:

  1. Install ctags
    e.g. aptitude install exuberant-ctags
  2. Configure ctags.
    Add to ~/.ctags the following, one option per line:

    1. --python-kinds=-i
    2. optional: --exclude=<partial names of bad files/directories>. e.g. --exclude=*/build/* to exclude all files inside 'build/' directories
  3. Add a cron to rebuild tags, for instance:
    1 * * * * ctags -R -o ~/mytags ~/src
  4. Configure vim:
    add to ~/.vimrc: :set tags=~/mytags
  5. Use Vim:
    1. vim -t <tag name> to open vim straight on the tag
    2. Ctrl+] to jump to tag when over a word
    3. Ctrl+T to pop back
    4. :tselect or :stselect to open
    5. :tnext, :tprev to go to next/prev tag finding
    6. :help tags for more 🙂

Surprising new keyboard shortcuts

(Well, surprising me, at least)

It's been a while since I wrote these two posts about keyboard shortcut, so I'll try to summarize some neat ones I've recently learned:

Unix Shell

  • Ctrl+U deletes all characters on the cursor's left. And.. keep it in the shell's clipboard.
  • Ctrl+K deletes all characters to the cursor's right (including the cursor's position), keeps in clipboard.
  • Ctrl+Y: paste clipboard.
  • Ctrl+R: search for string in history. Multiple Ctrl+R's search for the next matches in history. Btw, It's F7/F8 on windows command prompt.

Google vim keys and more

  • Google search: Google Experimental Search, enables vim keys for browsing the results! Super useful.
  • Google Calendar support vim keys (j, k, l, m) for navigating in the calendar. Type "?" for more keyboard shortcuts.

GNOME

  • Alt+F10 toggles between maximal window size and original window size.
  • Alt+F9 minimizes window
  • Alt+F8 switches to resize window mode
  • Alt+F1 opens the GNOME menu.

Thanks for Zohar and Aviv for presenting me with most of the above shortcuts.

The most annoying Office feature can be disabled

I find the Autocorrect feature very annoying. Especially the annoying auto-capitalization thing, which prevents me from writing a single lowercase letter. All these years of wrestling with office are now over!

  • OpenOffice 2.4 (maybe 3.x as well): Tools -> Autocorrect -> Options tab
  • Office 2007: Round office button on top -> Word options -> Proofing -> Autocorrect options -> Autocorrect tab

Huh! I disabled them all.

I'm still looking for the "Disable all annoying behavior" checkbox..

Gallery2: displaying photo date & time

When viewing an album using Gallery2, each photo has a "Date: dd/mm/yy" line underneath.

The EXIF plugin can automatically detect the date & time the photo was taken on, but only the date is displayed by default. I find the time also important, so I wanted it displayed as well, in the "dd/mm/yy, HH:MM" format.

Unfortunately there's no nice GUI for setting this. It can be done, though, by modifying a line in the file /usr/share/gallery2/modules/core/templates/blocks/ItemInfo.tpl:

From:

{capture name=childTimestamp}{g->date timestamp=$item.originationTimestamp}{/capture}

To:

{capture name=childTimestamp}{g->date timestamp=$item.originationTimestamp format="%D, %R"}{/capture}

The date-template format ("%D" "%R" etc) is explained in PHP's strftime() help page.

Nmap service detection

Many times people do port scans to get the list of services which are alive; however sometimes (i.e. on heavy load) the port is reported to be open, but the service does not respond (or responds after 1 minute..).

Well, surprise! (to me, at least): nmap can recognize the service behind the open port and its version! It's called 'service/version detection'.

This is useful for many purposes, one use is simply running:

nmap -A <ipaddr>

to get the list of service behind the open ports.

And for the topic I began this post with, it can be useful for listing the services (i.e. ssh) which are actually open and responding in a network, with a command like that:

nmap 192.168.0.0/24 -sV -p 22 --host-timeout=2s

Of course few greps would make it nicer. Fun!

People of the world: migrate to UTF-8!

The Unicode issue is usually irrelevant in countries which use Latin letters only, but is very relevant to the rest of the world.

Every time when I saw 'Unicode support added' in OS/software changelogs I've been thinking "I couldn't care less", but that was stupid. Because when 100% of the software would speak Unicode (or more correct: UTF-8, which is the most popular Unicode implementation), the world would be a happier place to live in (but would still burn because of the global warming). Here's how I migrated:

Continue reading

Memtest86+

Memtest86+ is a cool utility to test the RAM for badness. It runs as a boot CD, so it doesn't care which OS is installed, if at all.

Actually it also comes with Knoppix, CentOS, Fedora CDs and can be run by typing "memtest" in the boot prompt , but can also be downloaded and burnt separately.

vim & ls colors (dark blue over black.. what were they thinking?)

I like black backgrounds. Less radiation to the eyes, less energy consumed off earth.. Unfortunately most of the time (Browser, Office) we are forced to use white background. But at least terminals can be made black easily.

The problem with black terminal is the dark blue color, which really hurts to read over black background. The solution:

  • /bin/ls: (I hope you use the --colors alias by default..)
    LS_COLORS environment variable should contain di=01;34 (instead of the common di=00;34).
    In Fedora, CentOS it can be easily configured from  /etc/DIR_COLORS.xterm    DIR 00;34 -> DIR 01;34
  • Vim: (I hope you don't use another editor..)
    add set bg=dark to /etc/vim/vimrc or ~/.vimrc.
    alternatively add colorscheme: <your favorite colorscheme>, such as  evening.