Tuesday, September 26, 2006

Going deep?

Every so often, we have a longish path that we navigate to open a file. e.g.
$vim ~/xxx/yyy/ddd/eee/fff/file1.txt

While editing, we realise we want to open file2.txt which is in the same directory as file1.txt
I find it very annoying have to type :sp ~/xxx/yyy/.....
The other option is to close vim, navigate to the said directory and open the files, which too I find annoying.

There is solace - two solutions

1) Use the command :cd %:h in vim 6 to navigate vim to the particular directory the file that you are editing is placed in. Now you just have to do a :e file2.txt to open the other files.

2) I don't like that solution either because, I change my vim's path. What if I want to open a file from the original place I started vim. Add the following to your vimrc:

if has("unix")
map ,e :e =expand("%:p:h") ."/"
else
map ,e :e =expand("%:p:h") ."\\"
endif

Now in command mode, press ",e", presto, the directory path gets filled in! You can continue to use :e for the original directory you started vim in.

Get a load of vimdiff!

I assume that being any *nix junkie, you would know what diff is used for. But plain diff sucks - it is not very clear as to which files had what in them. One first executes


Try vimdiff instead - the color coding of differences is very nice,(especially when vim folds all the code that is common).
Alternately, go for the gui - gvimdiff.

Usage(there is just one step here):

$gvimdiff file1 file2

Here is another goodie - you can edit file1 or file2 when they are opened in gvimdiff. Thus, you can make one file look like another while viewing the differences - how cool is that?

Lets make it more better, eh?

Assume you are editing file1 using vim, and now you want to do a diff with file2

All what you need is to type the following commands within vim!

:sp file2
:windo diffthis

Monday, September 25, 2006

Workaround for globbing or pattern matching on http with Wget

Don't you love wget? The fact that you don't need a browser to save a file.......hmmm....niiiice.

You might have noticed that you can do something like
$wget ftp://ftpserver.com/*.pdf
and it retrieves all *.pdf files for you

However, (you must have expected a catch - there always is) you cannot do the same with http.
i.e.
$wget http://httpserver.com/*.pdf
will give you an error!

This is because http retrieval does not support globbing! (What is globbing? - it is just using the *.pdf or any of the regexp kind of thingies [ ] )
What is your workaround? Use the command below:

$wget -r -l1 --no-parent -A.pdf http://httpserver.com/

-r -l1 means to retrieve recursively , with maximum depth of 1. -
-no-parent means that references to the parent directory are ignored
-A.pdf means to download only the gif files.
-A "*.pdf" would have worked too.

Happy globbing with wget on http servers too from today .... :)

Friday, September 22, 2006

Make bash behave like vi!

If you are like me, you like vi and vim!

Don't you wish every editor in the world had a vi option?

Well, you have something for bash prompts!

To make bash prompt behave like vi, just do
set -o vi
at the prompt, or add the line to your .bashrc.

Now, the wonders of vi are usable at your bash prompt (type something, press ESC and now press 0, it should take you the first letter, now press $, it should take you to the end)...

vi ROCKS! Happy vi..er....happy vi-ing!
{And I take another step into the deep dark side of geekiness :( }

Thursday, September 21, 2006

Go back in time with Vim 7.0

In Vim 7.0, a feature has been included which allows a user to jump back or forward to any point of editing.

For example, I am editing a document and after a couple of minutes (say 10 min), I realise that I have made a mistake. I can easily take the document to a point 10 minutes back by using the command-
:earlier 10m

Or for that matter, move to a point 5 seconds ahead by using the command:
:later 5s

Friday, September 15, 2006

Changing aspect ratio in gnuplot

Have too many benchmarks or simulation points? Want to change the aspect ratio?

To change the size of the eps image, use "set size 1.0,2.0" (where 1.0 and 2.0 are multiplied by the default 5 inch width and 3.5 inch height)in gnuplot. use "set size" to restore defaults.

Wednesday, September 13, 2006

Space inside math environment in LaTeX

Inside the math environment($-$ ring a bell?), LaTeX ignores the spaces you type and puts in its own spacing that it thinks is best.
To cheat the system, use the following:

\; - a thick space
\: - a medium space
\, - a thin space
\! - a negative thin space

Converting windows text files to linux compatible text files and vice versa

Don't you hate it when the line breaks get screwed up when you open a windows text file in linux, or a linux text file in windows?
This is the solution:

To convert a Windows file to *nix, enter:
dos2unix winfile.txt unixfile.txt

To convert a *nix file to Windows, enter:
unix2dos unixfile.txt winfile.txt

Thursday, September 07, 2006

See all available styles in gnuplot

Within the gnuplot window, type "test". It should bring up a plot showing all available colors and styles.