Friday, August 27, 2010

Vi commands .... which make life easy !!

Here I will put some really handy vi short-cuts. I am putting only those vi commands which a newbie can remember quickly and start using vi from now-onwards.

Note: Do not forget to press "Esc" first and the start following commands.

1) [n]dd :: Pressing 'dd' will cut the current line. If you press say '2dd' it will cut two lines.

2) [n]yy :: Pressing 'yy' will copy the current line. If you press say '2yy' it will copy two lines.

3) p :: Pressing 'p' (small p) will paste the copied/cut line(s) starting from the next line with respect to cursor.

4) [n]<< :: Pressing '<<' will shift current line by one tab. If you press say '2<<' it will shift the two lines counting from the current line(inclusive).

5) [n]>> :: Same as '4' but it will shift right.

6) /guru :: Pressing '/' then typing the text to search will search the text you have typed. But this search is case sensitive.

7) :set ignorecase :: To make you search case insensitive. Now onward you all searches will be case insensitive.

8) :set noignorecase :: To reset the '7' to case sensitive.

9) uu :: Pressing 'uu' will undo you last change. But if you keep pressing 'uu' several times it will keep redoing in reverse order of changes you have made.

10) Ctrl + r :: Pressing 'Ctrl+r' will do redo work for you.

11) ZZ :: Pressing 'ZZ' is same as ':wq'

12) D :: Pressing 'D' will delete current line starting from the cursor position to end of line. All text behind the cursor will remain as it is.

13) R :: Pressing 'R' will take you into replace mode. Meaning if you type over some text it will replace that text with letters you have typed.


Keywords:: vi cheats, vim cheats, vi commands, vi commands cheat sheet

Wednesday, August 11, 2010

Setting Virtual Host on Linux (Ubunut 10.04 -Lucid Lynx)

Here I am going to describe very briefly how to set up virtual host on apache2 on Ubuntu 10.04
Step 1: Create a your own folder lets call it 'myproject'. Create a simple html file inside this folder

Step 2: Go inside 'myproject' and create a file 'index.html' and put following code in this file

‹ html ›
‹ body ›
It works !!
‹/body ›
‹/htm ›

commands:
> mkdir myproject
> cp -r myproject /usr/share/doc/
>sudo ln -s /usr/share/doc/myproject /var/ww/myproject

Now at this point of time you have created a test to check if your virtual host setting is working fine or not

Step 3: creating virtual host
>sudo vi /etc/apache2/sites-enabled/000-default
Now add following lines in this file
--------------------------------------------------
VirtualHost *:80
ServerAdmin xyz@gmail.com
DocumentRoot "/var/www/myproject/"
ServerName myproject
‹/VirtualHost
--------------------------------------------------
Step 3: >sudo /etc/init.d/apache2 restart
Step 4: >sudo vi /etc/hosts
and add following lines in this file
-------------------------------------------
127.0.0.1 myproject
yourIP myproject
--------------------------------------------
Step 5: Set no proxy for 'myproject'

Step 6: Open http://myproject

If any php script present is myproject folder is not working add following line in virtual host setting file

LoadModule php5_module /usr/lib/apache2/modules/libphp5.so

So your final Virtual host setting will look like as follows
--------------------------------------------------
VirtualHost *:80
ServerAdmin xyz@gmail.com
DocumentRoot "/var/www/myproject/"
ServerName myproject
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
‹ /VirtualHost

--------------------------------------------------

For any doubt feel free to ask !!