Monday, October 31, 2011

Vim Tips

1.I always wished that as a programmer , I should not waste my time in
 writing the trivial stuff, the one I require every time I sit to write the
 program. For example, while writing any C-program, we have the general
 format of #include<...> & then main() {  ... return 0 ; }
 What if every time I start writing the program, this format is ready for me
 ?? Well thats possible, atleast with "vim".

Create the standard format of the file you want , lets say at <~/format> is
 the path.

Now start vim : vim ,& then type , in command-mode ---> :r
 ~/format ,thats all , whatever is in the file <~/format> will be simply
 pasted .

I have created the file : <~/lic.c> , it contains the GNU GPL disclaimer.
 Now after I finish writing the program , I just have to say ( in command
 mode ) --> :r ~/lic.c , thats all, the license-terms get pasted .
 It looks like this :
 /* ########################################################################
  *
  *LAST UPDATED :

 *Copyright (C) 2011 Lokesh Walase
  *
  * Released under GNU General Public License v2.0+ .
  * FOR DETAILED LICENSE, SEE THE END OF THIS PROGRAM.
  *
  *########################################################################
  */

/*####################################################################################################################
 *
 *This program is free software; you can redistribute it and/or modify
 *it under the terms of the GNU General Public License as published by
 *the Free Software Foundation; either version 2 of the License, or
 *(at your option) any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 * Visit
 *
 *To  receive a copy of the GNU General Public License
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *Boston, MA  02110-1301  USA

*The GNU General Public License does not permit incorporating this program
 *into proprietary programs.
 *
 *
 ########################################################################################################################
 */

2.As you might have noticed , the <~/lic.c> has the field --> LAST UPDATED
 :  , now to put the date & time here , go to that line, & in command mode
 ---> :r !date .

3.Well, if that didnt really raise your eyebrows, here's somemore . What is
 the best thing of the "terminal" ?? Yes, it "auto-completes" the commands
 by '\t' key. Now what if the same feature of "auto-completion" is present
 everywhere & not only in the "terminal" ?? Well thats possible, (again)
 atleast with "vim" .

Create a new <.vimrc> file in your home-folder . Say : vim .vimrc , at your
 home-folder & then copy paste this code( I found it on net ) :

        *function! Tab_Or_Complete()
          if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
                  return "\"
             else
                         return "\"
                endif
         endfunction
          :inoremap =Tab_Or_Complete()
          :set dictionary="/usr/dict/words"
 *
 Pls be sure of the indentation ,everything has to be strictly indented . I
 dont know what exactly it is doing .
 Now vim will "auto-complete" any words you type , press '\t' for the same .
 Its indeed cool ........proud to be a "vimmer" !! ;)

4.Now whats next ?? Well, enough of vim. Recently I came to know of the
 command that can convert .pdf files to text-files, post-script files ,
 html-files & many more. Just type in the terminal & then you press
 '\t' twice to see all the options .
 Reading man pages is boring , so u may convert a lengthy man-page to a html
 file & get a nice look & feel to read it , I did it for "info flex" .
 Type : info flex > flex.odt . Now open flex.odt & get its pdf format , &
 then use command --> pdftohtml flex.pdf flex.html


Ref : http://groups.google.com/group/cofsug/browse_thread/thread/d5edacf343486d03?hl=en-GB



 

No comments: