Category Archives: hacks you can live without - Page 2

vim as a syntax highlighting capable pager

Just thought I’d share what I learned sometime back.

Do you ever wish that you could “cat” a file and have it displayed on the terminal with syntax highlighting ? Well, “cat” is a tool for concatenating files. It does not know (or care) where it is cat-ing to (for that matter, it does not know or care, where it is cat-ing from either)

OTOH, Pagers (like ‘more’ or ‘less’) are tools to view files on the terminal. That said, vim also behaves somewhat like a pager when invoked using the command ‘view’. However, this does not do syntax highlighting, nor does it take input from stdin (ie: executing “cat /some/file | view” does not do what you expect). So what do we do ?

Well, we use a little a vim trick:

  • Look for the file /usr/share/vim/vim<version>/macros/
  • create an alias for that script:

    $ alias vless='/usr/share/vim/vim/macros/'

    (you may also save the alias later in ~/.bashrc if you like the way it works)

  • now use vless as you would use less

    $ vless foo.c
    $ cat /some/file | some_filter | vless

Nice huh ?

Mozilla Ubiquity — They weren’t kidding when …

I use firefox (who doesn’t ?) and every once in a while, i look for extensions that might be useful, or may improve my browsing experience, or just be plain fun !.

However, this last time I did that, it was a completely different experience. I saw something which reminded me that firefox is not just any ol’ browser. It is the browser.

The good folks at Mozilla are not kidding when they encourage you to “recalim the web”, they aren’t just advertising when they ask “Can a browser really make the Web better?” and they definitely are not being unrealistic lofty idealists when declare that “The Internet should enrich the lives of individual human beings.”

Here is proof — The Mozilla Ubiquity extension.

I do not want to even attempt describing this extension because I know, I’ll fail miserably. Instead I urge you to watch this introduction.

Ubiquity for Firefox from Aza Raskin on Vimeo.

I seriously think, things like this will affect the way people interact. It is not just about this particular extension, but what will follow when mash-ups like this become common place. We will take control and truly relaim our own personal web.

Mozilla is doing to the web, what linux did to Operating Systems ! What do you think ?

I <3 vim !

I’ve been a vim user for a long time. I’ve always liked vim, because the modal interface fits my brain and the keybindings, my wrists (which never really liked emacs).

Now, although I have used vim for a long time, I often tend to use a small subset of the power that this awesome editor offers.

I would like to say that this is because “what I know, is all that I need to know”, but the simple truth is it’s because I am too lazy to read the docs.

That said, I *do* sometimes feel the urge to become more productive, which leads me to invest time into really understanding my basic tools (vim, firefox, thunderbird, pidgin, windowmaker, aterm/xterm/rxvt).

Today, I decided it was going to be vim. Here’s what I learned:

  • Since version 7.0, vim has a builtin spell checker (“:help spell”; I was using the vimspell plugin all this while).
  • The ‘-x’ option [1] ! Look it up !
  • vimgrep (“:help vimgrep”)

Since I was so impressed with what I learned today, I’m listing down some of the things that I do know about. Some of these, you might already know, and if you don’t, I think you should.

Note that I’m not explaining any of these. This is more like a quick-n-dirty, see-and-do, reference. So, I’d suggest open up a decently large text file (something with more lines than your window size) and try out what’s listed. If you like what you see, the vim doc is beautiful, just pull out the help topic mentioned to learn more.

Note also that most of these refer to ‘command’ mode, ie: You need to press ‘Esc’ before trying any of these out.

  • visual mode (“:help visual”) – Not spectacular, if you already know about it. If you don’t, do a ‘v’ and move around the text, yank-n-paste, you’ll get the idea.
  • visual-block (“:help visual-block) – Now, this one, I’ve seen a lot of ‘old’ unix guys didn’t know about (which is a bit strange). Anyways, do a ‘Ctrl-v’ and move a couple of characters left/right and then up/down, yank-n-paste, you’ll get the idea …..neat huh ??
  • folding (“:help fold”). In visual mode, select a few lines, do a ‘zf’. To open, do a ‘space’ or ‘zo’ on the fold.
  • Editing an entire block – Using a visual-block, select a set of lines. Now, without pressing Esc, try some editing commands, like type in ‘I’ followed by #. Now, press Esc.
  • Inserting special characters in your search-and-replace patterns: An example is best for this one. Do this:

    Create a file with the contents:
    <HTML><HEAD><TITLE>42</TITLE></HEAD><BODY>The answer is</BODY></HTML>
    Do a ":1,$ s/></>Ctrl-v+Enter</g"

    See what I mean ?

There is so much more, but now I am bored …and I think at least for those who have not invested time in learning vim by reading the docs, at least some of this stuff would be new.

Maybe, I’ll post about vim again later. Till then though, here’s something that you could possibly use — My vim files. Just untar, rename the contents correctly (ie: mv {dot_,.}virc && mv {dot_,.}vim) and copy them to you $HOME. The .vimrc is written from scratch and mostly well commented.

Thanks for reading.

[1] wtf !! …and I’ve been breaking my head over getting an nice, easy to use and small tool for storing sensitive stuff (like account numbers, login/passwords, etc) and was left unsatisfied with all the fancy GUI tools and the CLI one’s I’d have to install separately on each new system)

UPDATE: The default encryption algorithm used for the -x option is breakable. It is the same as that which Pkzip uses (and has documented). So, -x is probably not a good idea for ultra sensitive stuff, but good enough and convenient enough for short lived files which don’t need high level of security. For proper encryption support in vim, I would recommend using Noah Spurrier’s OpenSSL vim plugin. . (Now included in the vim files link above).

Bash command line editing for lazy, vim users

Here’s a list of shortcuts I use frequently to make my time on the bash command line prompt a bit more efficient. Some disclaimers …

  • Although, I am a vim user who never quite attained the precise finger deftness demanded by emacs and yes, I do know about the vim command line editing mode for bash. However, I have realized that the vim mode is even more painful than most of the emacs-inspired (or rather readline specific) shortcuts listed here.
  • This is not a comprehensive list of shortcuts for bash. These are just the ones I find useful but have difficulty remembering sometimes due disuse (which causes muscle memory loss).
  • Some of these are not required if you are using a capable terminal (for example, if the terminal maps the Home and End keys correctly, those can be used instead of C-a and C-e respectively … however, this is what causes the muscle memory loss mentioned earlier).

Note: C == Ctrl, M == Meta (or Alt)

  • Tab for command and filename completion
  • C-l to clear the screen
  • Up and down arrow keys for browsing command history one at a time

Moving about:

  • C-a or “Home” to move to start of line– C-e or “End” to move to end of line
  • M-b to move a word backward
  • M-f to move a word forward


  • C-k to delete till the end of line
  • M-backspace or C-w to delete a word backwards
  • M-d to delete a word in place

Searching and inserting:

  • C-r begin searching backwards for matching string
  • C-M-y insert argument from last command here
  • M-. cycle through last arguments of previous commands

if …
$ echo foo bar
$ echo xxx yyy
$ echo “M-.” yields yyy, another “M-.” yields bar

Major editing:

  • C-X C-E to edit the current command using $EDITOR

Well, that’s about all I can remember right now ! Thanks for reading.

Marvell Technology Group Ltd. 88w8335 [Libertas] 802.11b/g Wireless (rev 03) on Fedora 8

Ok, I accept that I suck at updating a technical blog.

Anywhichways, here is a quick and dirty howto on configuring the “Marvell Technology Group Ltd. 88w8335 [Libertas] 802.11b/g Wireless (rev 03)”[1] PCI wireless card on Fedora 8 using ndiswrapper.

# make sure you have added the livna repository to your yum configuration
rpm -ivh

# install the ndiswrapper package
yum install ndiswrapper

# get the windoze drivers for the Marvell card

# Install the driver
ndiswrapper -i mrv8335.inf

# Make sure the driver is installed correctly
$ ndiswrapper -l
mrv8335 : driver installed
device (11AB:1FAA) present

# Create the configuration for modprobe
ndiswrapper -m

# Configure the card
$ system-config-network

beyond this, use your head.

Hope this helps someone out there. If you have questions, feel free to ask.

[1] This is what I am talking about:

$ lspci -v
05:04.0 Ethernet controller: Marvell Technology Group Ltd. 88w8335 [Libertas] 802.11b/g Wireless (rev 03)
Subsystem: Netgear WG311v3 802.11g Wireless PCI Adapter
Flags: bus master, 66MHz, medium devsel, latency 32, IRQ 18
Memory at 50020000 (32-bit, non-prefetchable) [size=64K]
Memory at 50010000 (32-bit, non-prefetchable) [size=64K]
Capabilities: [40] Power Management version 2
Kernel driver in use: ndiswrapper