Archive for the ‘linux’ Category

Advanced Vim Tutorial

Wednesday, March 29th, 2006

Vim is not just an editor. It can be an IDE if used at its best. I have found it more convenient to use than any other word processing tool i have used. With proper knowledge of the countless features provided by vim, one can be much more efficient in whatever editing job, and programming in my case.

Every time i wished for a feature, i found it there in vim. I didnt allow myself to do anything the stupid way, and always figured out a better way to do the same thing. Thats how i have got a decent expertise on vim. With this tutorial i wish to give you a feel of what all is possible with vim, and show you a direction to learn more.

Before i proceed, i would like to ask you a question. Suppose you have got a file with about 50 lines only, and you have to make few changes to the file. Lets assume that you are asked to add 10 to every number present in the file. Lets assume that there are only 25 numbers in the file and rest is text. Would you start doing it the stupid way or search for a efficient way to do it ?
Most of the times one will think that its just 25 numbers, and without thinking about a better way to do it, he just starts doing it right away. Or even if one does want to do it a better way he doesnt do it thinking that figuring out the better way will take much more time than doing it the ‘obvious way’. But what we always ignore is that its not just this time. We do it many times, and thats why it makes sense to go for the better way to do it, even if it takes more time at first time.

So next time when the thought “its just this much” comes to your mind, just remember that “its not just this time” , and the choice is yours.

If we go by Brook’s words “The tool that save the most labor in a programming project is probably a text-editing system” [The Mythical Man-Month, proposition 12.10], then we should probably work on our editing skills more than our programming skills.

In this tutorial I assume the reader to have a basic knowledge of vim. Basic features like editing, movement, searching, replacing, opening, saving etc not covered in this tutorial. I’d recommend going through vimtutor for basic understanding of vim.

Lets start.

Link to the tutorial (pdf)

“if its just this much, its not just this time”


This tutorial was prepared for my guest tutorial on March 28, 2006 for ug1 batch.
Updated May 12th, 2006 with features of vim 7.0 ( Tabs, Undo Branching and Spell Checking).

Thanks to Paresh Jain for helping me with LaTeX. Otherwise it wouldnt have been possible to write it using vim and I wasnt doing fair to it by writing it in anything else.

related -
* vim recording

svn server for multiple repositories

Tuesday, February 7th, 2006

svn allows any user to run the svnserver, but this creates a problem when more than one user wants to create svnserver on a system. the user can work around by specifying a different port, but here i give a better solution for it.

run a svn server and set the root directory as world writeable directory, where anyone can create a softlink to his repository. i set it to /home/svn.

adding a service for svn server makes things better. it will help to automatically start the svnserver on system restart. here is the xinetd file for svn server.

# default: on# description: The svn server serves svn sessions \# create a soft link of the actual repository in /home/svn/

service svn{        disable = no        port                    = 3690        socket_type             = stream        protocol                = tcp        wait                    = no        user                    = root        server                  = /usr/bin/svnserve        server_args             = -i -r /home/svn}

put the above in /etc/xinetd.d/svn and restart xinetd service and make /home/svn world writeable ( chmod a+rwx /home/svn; chmod +t /home/svn )

now just create a soft link of your svn repository in /home/svn with any name and you will be able to access the repository with the name of the soft link you created. to test just run svn list svn://localhost/<soft-link-name> and you should be able to see the contents of your repository.

vim :: recording

Sunday, March 13th, 2005

many times i accidently q and got the annoying “recording” message at the bottom. Some times even made crazy to quit out of vim.

So what is this recording thing in vim…
It actually records your keystrokes, and you can execute them later.

How to use it ?
In normal mode ( normal = !insert && !visual ), press q and an identifier for your recording (another key). This would start recording your keystrokes and the message “recording” will appear at the bottom of the screen. And to end the recording press q (in normal mode).

Summary -
qx -> start recording (in buffer x) . (in normal mode)
do any work
q -> stop recording, (in normal mode)

Example -
to add <html><body> at top and </body></html> at bottom of a page you can record keystrokes like this
qm1<Shift+g><Home><Insert><html><body><Esc>
<Shift+g><End><Insert><Right></body></head><Esc>q

Example Explained -
qm -> start recording ( to register m)
1<Shift-g><Home> -> go to start of the page
<Insert><html><body><Esc> -> enter insert mode and write <html><body>
<Shift-g><End> -> go to end of the page
<Insert></body></html><Esc> -> enter insert mode and write <html><body>
q -> stop recording

How to use the recorded keystrokes ?
@ and the keyword corresponding to your recording (in normal mode)
for example to use the above macro, we will type @m (see qm => record into register m)

Sometimes another annoying window open, when we accidently type q: (instead of :q, maybe)
It is commandline window. to quit out of it simply press enter or type :q (it wont quit the orignial buffer)

NB:
These recordings are not intelligent. They are just keystrokes recorded, and will be executed as such. You have to make your keystrokes intelligent.

My doubt : Reference -
:help q
:help q:
vim.org/Tip #144: recording keystrokes by “q” for repested jobs
is there any difference between this recording and macros ( in general and in vim) ?

References -
:help q
:help q:
vim.org/Tip #144: recording keystrokes by “q” for repested jobs

* Advanced Vim Tutorial - other strong features of vim.

Microsoft Windows Services for UNIX (SFU)

Thursday, March 3rd, 2005

provides a range of cross-platform network services that help to integrate Windows and UNIX-based environments. It provides seamless access to information stored in multiple platforms, consolidates network management across platforms, and reuses UNIX applications and scripts on Windows. It provides NFS server and client, POSIX subsystem which provides UNIX layer on NT and Server for NIS and password mapping. It allows you to run your Windows machine through a Unix shell by mapping directly to Active Directory (AD).

A talk at IIIT by Rajesh Jalan, Microsoft Research.

Well, M$ is trying hard to enter the Server business. Okey atleast they realized that they have to “integrate Windows with UNIX-based environments”. Trying to learn NFS, claim to run POSIX executables, and S-NIS. U know what it means. More bugs.

I appreciate the work. S-NIS sounds good to me. A good way of centralizing the information in a big network. But what is wrong is Windows. A millions of lines of code, with dont know how many bugs. I double click and it says “You have performed an illegal operation. Do you want to send the report”.

Why can’t things be as simple as gnu. A kernel, init and then other processes. Mean i can understand the structure. Well they too claim to have a kernel, but i never understood which part of it is kernel, which is GUI and which are applications. The GUI, and the applications looks like an integral part of the OS, maybe the kernel.

Okey, I’m not too good at these things, but i believe that M$ has lots of brain (purchased), and they can make a great OS, if they start something from scratch, and stop fighting with a million code lines virus.

Before I started writing this post, I didnot actually wanted to write all this. I just wanted to mention my dream project some 2 yrs back.
To write a Linux like kernel, which runs on top of windows, and use the space of installed gnu as root, and run like you are running the actual gnu. Its like implementing basic functions of Linux like IPC, signalling, file system, etc on top of windows. Should not be very difficult. I see it as simple as providing system calls to any program working on top of it, and as soon as the system calls are provied i should be able to run any gnu application on it. If any OS guru happens to read it, pls let me know some inherit difficulties in doing so.
Anyway i am no more interested in the project. Who cares. I dont want to be one to contribute to the bugs database of windows.