VIM Part II – Basic Navigation and Editing

It has been a long time since I blogged about the how to get started with VIM. So without delay I should start with basic navigation and editing in VIM. Before that I just want to say that VIM is very case sensitive (in command mode). “A” is not same as “a”. So if I type “A” it means “A” and not “a”. There are a few different modes in VIM
  • Command Mode
  • Insert Mode
  • Search mode
When you start VIM, it will be in command mode. In command mode you can move cursor, delete text, search and replace text, navigate in the file. For inserting text you will have to use “insert” mode. You will not be able to insert text in command mode. Here are the keys for basic navigation: Move Right ==> l (Small L) Move Left ==> h (Small H) Move Up ==> k (Small K) Move Down ==> j (Small J) These shortcuts are for people who want to be as fast as fast possible while typing because you do not have to break the flow of your typing with the above navigations. For people who do not like this the normal Up, Down, Right and Left arrows on their keyboards will work as well :). For inserting the text you will have to press “i” (Small I) while in command mode. After hitting “i” you will no longer be in command mode and pressing “l”, “h”, “k” and “j” will actually print these letters. In insert mode you can type in the text as you do normally. To get out of “Insert” mode, press “Esc” key. Search mode is invoked by pressing “/” in command mode. After that type for whatever you want to and hit the Return key. Press “n” (Small N) to go to next searched item and “N” (Caps N) to go to previous search item. What makes VIM an editor of choice is its command mode and the way you can navigate within it without touching mouse. Here are some commands(which I know and use): gg ==> Go to first line in the document G ==> Go the last line nG ==> Go to line number “n”. 25G takes you to the 25th line in the document. c$ ==> Chage to the end of line cw ==> Change word dd ==> delete current line ndd ==> delete next n lines where n is any number yy ==> copy current line to buffer nyy ==> copy n lines to buffer P (small) ==> paste above the line where cursor is p (caps) ==> paste below the current line where cursor is o (small) ==> Add a new line below cursor position and invoke insert mode O (caps) ==> Add a new line above cursor position and invoke insert mode The “dd” puts the deleted lines in buffer so it can be also used as cut-paste in conjuction with “p” or “P” command.

VIM Part I – Get a basic VIM up and running

Recently, I “buzzed” that how much I love VIM. Then one friends thought of trying VIM. And by evening he had VIM un-installed from his system, terming it as an old tool in this age of bleeding edge GUI editors. This made me think that how many people dump VIM before even trying the features this editor has to give. So, here is my two cents to this editor.

I will try to write on how to setup this editor and then on we can go digging deeper. I use gvim on openSUSE 11.2 at home and on Windows XP at office. Barring a few different file names and file paths there is not much difference in the way gvim works in Linux and Windows. I will be specifying where ever and when ever required.

One thing, VIM is not an IDE, it is a simple (yet powerful) editor. It is not a replacement for Adobe Photoshop or anynthing like that. VIM is for people who like to “write down” their code. people who do not want to to take their hands off their keyboard. It is surely a blessing for LINUX/UNIX sys-admins. VIM is a VI like editor, VIM is VI Improved. And in addition to console editor, VIM also has a graphical front end GVIM, which brings the powe of VIM to the GUI. In all modern LINUX distros VIM is installed by default and you call only VIM when typing “vi” on the console, vi is aliased to vim. On windows you can download the EXE file from here. Download gvim72.exe. Direct link for gvim72.exe here. When installing on Windows, it will ask you for the kind of install, select “Full Install” there.

After installation the Windows user will get a batch file “gvim.bat” in C:\windows, it is this file which needs to be executed and not the gvim.exe found in C:\Program Files\Vim, that needs to be executed when we have to open gvim. But Windows users do not need to worry as whenever you type gvim in run command interface, it will always open gvim.bat. For Linux users, they can open gvim by typing in “gvim &” from the console (& will put the gvim in backgrouond in that console window), or type in gvim in Linux run command interface (Which can be opened by ALT+F2 in KDE). You will get a basic gvim running there.

This is it, installation is always the easiest way, it is the working with gvim which we have to learn. gvim is highly customizable editor, which you are going to know very soon. Gvim stores its settings in a file named “vimrc”. In windows the filename is “_vimrc” and it is located at C:\Program Files\vim. And, in Linux the filename is “.vimrc” and it is located at $HOME/.vim directory. If there is no vimrc file at these locations create them. If there is no “.vim” directory in $HOME, create it and then create a empty file “.vimrc” there.

For windows users there will be two directories in C:\Program Files\vim : vim72 and vimfiles. Whatever syntax changes, colorscheme changes any plugins that you add, they all need to be done in “vimfiles”i directory. And for “Linux” users it is the $HOME/.vim directory. This is to keep your customization safe when you are going to upgrade to future versions of VIM. e.g. VIM is going to release VIM 7.3, when you install that your vim72 directory will get irrelevant but you will not loose your customizations as the new vim installation will takje it from vimfiles folder, and in Linux it will be “.vim” directory. Other reason is that you can mess as much as you can with your vim, and if you screw it totally, you just need to empty vimfiles/.vim folder and everything will be fine again, then start again 🙂

So let’s make some basic changes in vimrc file and start editing… For winodws the changes need to be done in “_vimrc” and for Linux the changes need to be done in “.vimrc”.

Suppose you need to set you font to Lucida Console, 10 pt, Bold. To set your font
In Linux:


And in Windows:



Want to set a default colorscheme. Add this line to your vim:
Check the Vim color schemes sample here. Download your chosen colorscheme and put it in $HOME/.vim/colors (Unix) or C:\Program Files\Vim\vimfiles\colors (Windows) folder.

I am putitng my vimrc file here just for refrence. The comments in it explain what the commands do.

Note: ” in vimrc is for putting comment.
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/vimrc_example.vim
"I am a Cobol Developer :)
autocmd FileType cobol set sw=4 sts=4 et sta tw=7
set nocompatible
"Behave like Microsoft.. CTRL+P, CTRL+P stuff
source $VIMRUNTIME/mswin.vim
behave mswin
set nu "Display line numbers
set ignorecase
set smartcase
set nobackup
set nowrap
"Set file formats to Unix, the other options
"are ff=dos or ff=mac. If you open a file from 
"Windows while your gvim ff=unix, you will see 
"^M characters. These ^M characters are Windows 
"End of Line characters
set fileformats=unix
set guioptions=agimrLt;
"The following commands will indent your code the right amount, 
"using spaces rather than tabs and automatically indent after you 
"start.>>> 
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent
"<<< Complete indentation code
set autochdir
"Whenever I open or creat a file with extension pco, cpy or
"link, set its filetype to cobol, which will evoke proper
"syntax highlighting
au BufNewFile,BufRead *.pco set filetype=cobol
au BufNewFile,BufRead *.cpy set filetype=cobol
au BufNewFile,BufRead *.link set filetype=cobol
set diffexpr=MyDiff()
let cobol_legacy_code=1
let $p_h='/home/vivek/public_html'
set gfn=Consolas\ Bold\ 10
colorscheme ps_color
set cursorline
" Press Space to turn off highlighting and clear any message already displayed.
nnoremap   :nohlsearch:echo

"Tab navigation like firefox
nmap  :tabnext
nmap  :tabprevious
map  :tabprevious
map  :tabnext
imap  :tabpreviousi
imap  :tabnexti
nmap  :tabnew
imap  :tabnew
"Key map to copy the selected word and search it... Key Map: CTRL+F
map  /
imap  /
nmap  /
"Go Directly to Procedure Division in COBOL...
nmap  /PROCEDURE
imap  /PROCEDURE
"CTRL+Z --> Undo
imap  :u
nmap  :u
map  :u
"CTRL+O --> Open a new tab and also open a window to browse 
nmap  :tabnew\|browse e
imap  :tabnew\|browse e
"CTRL+W --> Selects word
nmap  bvw
imap  bvw
":%s#\s*\r\?$##
"ATL+M --> Trim trailing spaces
nnoremap  :%s#\s*\r\?$##
inoremap  :%s#\s*\r\?$##
noremap   :%s#\s*\r\?$##
"CTRL+Down Arrow --> Scroll page down
nnoremap  
inoremap  
noremap  
"CTRL+Up Arrow --> Scroll page up
nnoremap  
inoremap  
noremap  
"CTRL+F1 --> Toggle Shortcuts Bar 
nnoremap  :if &go=~#'T'set go-=Telseset go+=Tendif


This is just for getting a basic Vim running on your machine. Next I will write down how to do real work in Vim.
Let me know if I missing something in this post.

My Lost Home in Kashmir…


Video Produced by: Deepak Ganju Images: Veer Munshi & Deepak Ganju Song: Arti Tiku Kaul See at shehjar Magazine at: http://www.shehjar.com/list/94/840/1.html Each image of Kashmiri Hindu House is stark, plain-spoken, without embellishment. There is no annotati ve manipulati on of these images, no theatricality, no vein of melodrama, no overtly elegiac air, no demand for sympathy. There they stand, in our line of sight: ruins, monuments, memorials. This is testimony to the unforgiving march of history, which takes no prisoners. ‘Ranjit Hoskote’

Using Google Labs in Gmail

I have become a Google fan. It gives you everthing you need… Gmail – The mail cleint, Orkut – Social networking, Google Docs – Google office suit, Google Analytics – To analyze your website, Adsense – To make your website a source of income, and many many more. But the thing is the majority of even do not know how we can fully utilize the Google things. Today, I am going to share the Gmail features which have made me using Gmail more enjoyable and productive.
There are a few additional stuffs I use with gmail which make my using gmail just more useful. First you need to know about Google labs.Google labs has stuff which Google users think it should have :). If you are going to use gmail labs for first time, then go to your “Settings” and acess “Labs” from there.
The Wiki says “Google Labs is a website demonstrating and testing new Google projects”, so just take a note of this thing that Google labs may make your gmail unstable. But I haven’t faced any problem till now.
Now we will begin with the Gmail stuff.
  • Picasa Previews:
    Imagine you have been sent an invitation to view a Picasa Album, but you just want to have a preview of Snaps in the web album before deciding if you actaully want to view the whole album. This plugin helps you just doing that. Enable “Picasa previews in email by Dan, Stanley Mark and Umesh”.
    Enabling Picasa Preview in mail
    Enable Picasa Preview
    And you will be able to see the Picasa Snaps previews just in your mail whenever you receive any invitation from anyone to view their picasa album.
    Picasa Preview in mail
    Picasa Preview in Gmail
  • Google Docs Preview:
    This plugin let’s you view Google Docs directly in your mail. Enable the plugin “Google Docs previews in mail”.
    Enabling Google Docs Preview in mail
    Enable google docs preview
    After this whenver you receive any Google Doc, you will see a “Show Preview” option next to that Doc icon like below:
    'Show Preview' in Gmail
    ‘Show Preview’ in Gmail
    After clicking this “Show Preview” you will be able to directly view thw document…
    Google Doc preview in mail
    Google Doc preview in mail
  • Quick Links:
    Sometimes you get mails which you may need in future, or just want to access anytime. One thing which can help is Google Label, but creating a Label just for a single mail is not a great idea. What you can do is enable “Quick Links by Dan P” like this…
    Enable Quick Links
    Enable Quick Links
    And when you have “that” mail open click on “Add Quick Link” from “Quick Links” widget. A box will pop up confirming to add the quick link. Choose the name for your quick link there and click “OK”.
    Creating Quick Links
    Creating Quick Links
    Now you can access the quick link from the Quick Link widget on left side.
    Quick Links Widget
    Quick Links Widget
  • Superstars:
    How many times have you missed the variation in kind of “Stars” in Gmail. You can just start an item or not star it. Did you miss the functionality of having a graded start system, where you can set Red Star for an important mail, Green Star for a less important mail… Your search ends with this labs feature – Superstars. Go to Gmail Labs, and enable “Superstars by Kai H and Julie W”.
    Superstars
    Enable Superstars
    Then go to “Settings” and choose the Stars you want to use by dragging them from “Not in use” to “In use”.
    Superstars
    Setting up Superstars
    You can remove the Stars you do not want by dragging them from “In use” to “Not in use”. Now go to any mail and click on the Star there and keep clicking till you the appropriate star… 🙂
  • Pictures in Chat:
    This is what I always wanted in chat… This let’s you see the photo/avtaar of the person who you are chatting with. Just enable “Pictures in chat by Dave C” and you are done.
    Phots in Gtalk
    Phots in Gtalk
  • Signature Tweaks:
    Tell me aren’t you annoyed when Gmail places your signatures at the bootom of mails when you reply or forward a mail, normally we all want our Signatures to be placed just below the text we write or above the text of reply/forward. This labs feature let’s you just do that. Enable
    Phots in Gtalk
    Enable Signature Tweak
    “Signature tweaks” by Keith C and Dave C. Now when you reply or forward a mail your signature will appear as:
    Signature Tweak
    Signature Tweak
    Is this what you always wanted… 🙂
  • Old Snakey:
    I remember getting hooked to Snake on my Nokia 3315. With time that old Snakey got lost somewhere in the maze of technology, but I re-found that old snakey hidden in Gmail labs.. Enable “Old Snakey” by Dave C.
    Enable Old Snakey
    Enable Old Snakey
    Now relax, lay back and enjoy your favourite game, but do not forget to enable Keyboard shotcuts for Gmail before that, as you will need to hit “&” on your keyboard to play this game.
  • Right Side Chat:
    I do not like all the widgets stacked up on the left side in Gmail, especially the Gtalk widget. I always wanted Gtalk widget to be on the right side in Gmail, and “Right-side chat” by Emily C just let’s be do that. Enable it from labs page.
    Enable Right Side Chat
    Right Side Chat
  • Mark as Read button:
    You, like me sometimes want to mark some mail “Read” as quickly as possible. So, go and enable “Mark as Read Button” by Mark K from labs
    Enable Mark as Read Button
    Enable Mark as Read Button
    Now, you will see a button like this in your gmail.
    Mark as Read Button
    Mark as Read Button
  • Default Text Styling:
    Do you get irritated by always being forced to format the mail to set your font and colors before sending it. Now all you have to do is enable “Default Text Styling” by Jonathan K from labs.
    Enable Default Text
    Enable Default Text
    Now go to “Settings” tab and set you default font and color. From Now on you do not need to format your mails everytime before sending them.
  • Authentication icon for verified senders:
    This is just one more additional feature which helps you in not getting fleeced by someone on the big bad world of Internet. Enable “Authentication icon for verified senders” by E R…
    Enable Authentication
    Enable Authentication
    And you will be able to see this kind of key icon from certain senders which spammers try to fake.
    Authentication Icon
    Authentication Key
    And you will be able to see this kind of key icon from certain senders which spammers try to fake.
    Authentication Icon
    Authentication Key
    This only works for PayPal and eBay as of now.
  • Send & Archive:
    This feature let’s you archive a mail which you are sending. Enable “Send & Archive” by Pal T.
    Enable Send and Archive
    Enable Send and Archive
  • Undo Send:
    Oh… How could I hit the send button before finsihing it!!! Felt like that sometime? Now enable “Undo Send” feature by Yuzo F and you will never send intended or unfinished messages to anyone.
    Enable Undo Send
    Enable Undo Send Mail
    You will get two options with this feature:
    • Able to cancel sending mail.
      Cancel Sending of Mail
      Cancel Sending of Mail
    • Even if the mail is sent, you will be able to “Undo” the send, but this feature will be available just for a few moments, before the mail is delivered to the receipent.
      Cancel Sending of Mail
      Recall the sent mail
  • Title Tweaks:
    Do you need to switch to the brwoser again and again to know if you have received some new mail? Imagine if you get to know of any new mails from the minimized browser itself… Enable “Title Tweaks” by Fedor K.
    Enable Title Tweak
    Enable Title Tweak
    The minimed browser from your panel will look like this now:
    Title Tweak
    Title Tweak
    Telling you the number of mails in your Inbox.
  • Hide read labels:
    Have you created a large number of “Labels” to manage your mails… And obviously you do not want to all the Lables to take up all the space on left side in Gmail. So enable “Hide read labels” by Damian G & David de K.
    Enable Hide Read Labels
    Enable Hide Read Labels
    Now, only Labels which have unread mails in them will be displayed and others will be hidden which you can access by clicking the drop down arrow.
  • Inserting images:
    Want to insert images directly into your mail instead of sending them as attachments??
    Enable imbedding Pictures in Mail
    Enable imbedding Pictures in Mail
  • Extra Emoji:
    Feel Gmail does not have emoticons for your emotions :), enable “Extra Emoji” by Yuzo F and put your emotions in your mails
    Enable Xtra Emoji
    Enable Xtra Emoji
  • Google Docs gadget:
    If you use Google Docs extensively like I do, you may like this feature which displays a Goole Doc widegt in which your recent Google documents will be displayed. Enable “Google Docs gadget” by Claudia C and Ted C.
    Enable Google Docs Gadget
    Enable Google Docs Gadget
    Google Docs gadget will appear on the left side if your Gmail…
    Google Docs Gadget
    Google Docs Gadget
There is one more feature which is imbedded in Gmail itself but not many people know about it. Suppose you have logged in from some computer and instead of signing out, you just closed the browser and left. What if that computer is not a private but public computer!!! Gmail let’s you to sign out from all sessions other than the current one from the computer you are using. Just got to the bottom of Gmail, there you can see “Last account activity:”.
Sign Out All other Sessions
Click on “Details” just next to it, there you can see from which all IP’s you have logged into your Gmail account in recent past, and there only you can “Sign out all other sessions” and relax.

Non-compatibility between my website and IE8 yesterday…

Yesterday people who viewed my site in IE8 told me that the site is totally screwed up. In the evening I fixed the problem, and now hope that the Microsoft browser will not have any problems with my web site 🙂 .
1 4 5 6 7 8