Tuesday, April 30, 2013

Some useful gvim/vim tricks

Hi Here some very much useful commands are given for programmers who use gvim/vim as their editor.

Going Forward in file

Suppose you are seeing log of some code that you have written in some programming language. As I am ASIC engineer lets say System Verilog. Now in your log file there is some compilation error in some particular file which is shown with full path in log. right??
Lets assume that compiler is giving error in file
    /home/sandipb/temp/system_verilog.sv : Undefined Veriable

As you are using powerful gvim/vim software just put your cursor to that directory path which is shown in blue color in this post(you will have your own path in your log) and press "fg" and you are in the /home/sandipb/temp/system_verilog.sv

Back to Directory

Now after doing some necessary changes in the edited file you can go back to log file by simply typing the following command.

              :bd 
This the command for going back to directory.


Spliting file Vertically as well as Horizontally 

You can easily split your vim/gvim window using split commands. To split your gvim window use split  command.
 :split
And to split your gvim window vertically use vsplit command.
 :vsplit

In some cases where you want to directly open specific file in split mode. In this case simply give file path name as argument of split / vsplit command.
For example you want to open file ~/abc/xyz.txt in new splited window.
User command  :split ~/abc/xyz.txt or :split ~/abc/xyz.txt

Open or reload file in gvim/vim
Generally we use tabnew to open a file when we want new file to be opened in new tab and current working file remain open.
To open a new file without giving path. You can use :e filename command for this.
To reload the file just write :e

Auto word or line completion in gvim/vim
Programmers always need to define variables and need to use them. One basic requirement for using variable is that name should be same at all places !!!!!! For this thing gvim provides facility to auto complete you variable name.
Cntl + p & cntl + n used to auto complete the word. There is not much difference using cntl + p or cntl + n.
cntl + p auto complete the word in previous direction.
cntl + n auto complete the word in next direction.

Same way we have one auto complete command for completing lines.
That is cntl + l  this command auto complete the line.

These are the tricks to work faster that I am able to learn in my 2 and half year of experience.



Previous                                 Index


Tuesday, April 2, 2013

Configuration of .gvimrc for UVM highlighter

As we have discussed in previous post how we can create simple groups for highlighting purpose. I have created highlighter for UVM(Universal Verification Methodology).
If you want to learn how to code highlighter you can see it in following links.

                               Configuration of magic box .gvimrc

                               configuring color property for highlight group

                               define complex group for highlighting

I have configured some variables for highlighting purpose while using uvm methodology for verification. Simply copy this code in your .gvimrc/.vimrc file and it is done.


                    syntax keyword uvm_keyword uvm_object
                    syntax keyword uvm_keyword uvm_agent
                    syntax keyword uvm_keyword uvm_transaction
                    syntax keyword uvm_keyword uvm_sequence_item
                    syntax keyword uvm_keyword uvm_sequence
                    syntax keyword uvm_keyword uvm_sequencer
                    syntax keyword uvm_keyword uvm_report_object
                    syntax keyword uvm_keyword uvm_component
                    syntax keyword uvm_keyword uvm_monitor
                    syntax keyword uvm_keyword uvm_scoreboard
                    syntax keyword uvm_keyword uvm_driver
                    syntax keyword uvm_keyword uvm_test
                    syntax keyword uvm_keyword uvm_env
                    syntax keyword uvm_keyword uvm_subscriber
                    syntax keyword uvm_keyword uvm_config
                    syntax keyword uvm_keyword uvm_config_db
                    syntax keyword uvm_keyword uvm_analysis_port
                    syntax keyword uvm_keyword uvm_tlm_extension
                    syntax keyword uvm_keyword uvm_tlm_if
                    syntax keyword uvm_keyword uvm_field_int
                    syntax keyword uvm_keyword uvm_config_db
                 
                    syntax keyword uvm_function seq_item_port
                    syntax keyword uvm_function get_next_item
                    syntax keyword uvm_function try_next_item
                    syntax keyword uvm_function build_phase
                    syntax keyword uvm_function connect_phase
                    syntax keyword uvm_function run_phase
                    syntax keyword uvm_function uvm_phase
                    syntax keyword uvm_function raise_objection
                    syntax keyword uvm_function drop_objection
                    syntax keyword uvm_function run_test
                 
                    hi uvm_keyword term=bold  gui=bold guifg=red
                    hi uvm_function term=none  gui=none guifg=green


PREV PAGE                                           INDEX                                                     Next

Saturday, March 30, 2013

Defining Abbreviation in .gvimrc/.vimrc

We engineers are so lazy people. That is the most basic need for being a programmer. I mean who will like to type so much lines of code if it can be done easily. Gvim/vim gives us this facility for creating an abbreviation. As we know while programming in x language we might need to type certain line of code repeatedly. For example while coding in System Verilog I need to add display messages in many place.
User can create abbreviation as follows.

Suppose I want to create abbreviation for syntex. 
                        $display("sandip  :  "); 
This can be done as follows type the following command in your command line or just put it in your .gvimrc/vimrc file.
                            :ab $d $display("sandip  :");
After typing this command whenever you type $d and then press Esc or tab it expands to full string that we specified   $display("sandip  :");  This techniques of abbreviation saves your time from time consuming typing of code.

For C programmers the most useful abbreviation I would suggest is 

                           :ab #i   #include<stdio.h>  

currently I use the following abbreviation in my .gvimrc/.vimrc file. 

ab $d $display($realtime,"   sandip : ");
ab axidebug `axi_report_debug(log,msg_id,$psprintf(""));
ab axiinfo `axi_report_info(log,msg_id,$psprintf(""));
ab axierr `axi_report_error(log,msg_id,$psprintf(""));
ab ahbdebug `ahb_report_debug(log,msg_id,$psprintf(""));
ab ahbinfo `ahb_report_info(log,msg_id,$psprintf(""));
PREV PAGE                                                 INDEX

Configuring .vimrc and .gvimrc for Mapping Keys

As we know that computers do what we ask to do it and that is called programming. Or I can say programming is like giving instruction to computers. Mapping keys in gvim/vim is same. As we know that command for selecting all text in file is :ggVG  right?
What if I am not able to remember this???  Somebody will say that you have to remember it there is not any other option. But gvim/vim says "I have solution of this problem."
Gvim/Vim has facility of mapping commands, definition of mapping I can say that telling computer (gvim/vim in our case)  now onward you should perform this operation irrespective of whatever you were doing previously.

Get started with mapping 

Let's take an example suppose you want to map command :ggVG for selection of whole text in file to sel. Simply write following command in your .gvimrc/.vimrc file
                                    map sel ggVG
or for temporary use write command :map sel ggVG and now for experiment press "sel" in normal mode. Your whole text will get selected.

Now let's map some keys with commands. You can use <keyname> to tell gvim/vim mapping about special character. The following command maps space key for selecting word on which currently our cursor is.
                                    map <space> viw
after this put your cursor on any word and type space bar and gvim/vim automatically selects the word. One another example is map <c-d> dd maps cntr + d key with command dd. So after writing this command every time pressing Control + d deletes current line in file.
The following map will give you command for shifting your line in your text.
                                    map - ddp
after typing this your current line will shift one line below by typing just - in normal mode. Same way you can create such mappings as per your requirements.

you can use this command for creating abbreviation as gvim/vim do exactly we say it to do. As in first example we are replacing  ggVG with sel. But if mapping contains latter "i" gvimvim shift to insert mode. So if you want to create abbreviation it can be done as follows.
                            map fun ifunction
In this case first latter i takes gvim/vim into insert mode and then write function. So after this if you are pressing fun in normal mod it will give you function fully written. Also gvim/vim has facility to abbreviation.

you can ma function keys as well example map <F2> command.             

Modal Mapping

You can be more specific when you want to apply your mapped keyword by using nmap , vmap and imap for mapping in normal mode, visual mode and insert mode respectively.

The reason for these different commands is that the behavior of one mapped keyword will be differnt according to different modes selected.
you can disable any previously defined mapping by the following command.
                 :nummap mappedkeywore
suppose you want to remove mapping on key Control + d simply write :nummap <c-d>

 View Currently maped keys

 you can see which key have been mapped to which command. Gvim/vim shows you complete list of this type of key. Just type the following command 
                     :verbose map 
this command gives you complete list of files that have been mapped for current file.


 PREV PAGE                                               INDEX                                                      NEXT PAGE

NOTE: The above commands should be written to your .gvimrc or .vimrc file so that you can use it whenever you open gvim/vim. This will improve your code editing speed.

Sunday, March 24, 2013

define complex group for highlighting

Let's consider defining group for more complex text instead of strait forward word list.

Suppose you want to define group of any word consisting lower cases and want group name as Identifier. The following command makes group xidentifire which is lowercase.   
                                 :syntax match xIdentifier /\<\l\+\>/
Defining match for a comment. Let's assume that in x programming language anything after # to the end of the line is considered as comment.
                                :syntax match xComment /#.*/
Since you can use any search pattern, you can highlight very complex things with match items.

In x programming language strings are enclosed in double quotation marks. So we have to write a logic that match starts with quotation and end with first quotation after that. Command is written as follows.
                             :syntax region xString start=/"/ end=/"/
The "start" and "end" directives indicates start and end of the sting region. But as we know that sting can also be written as
                           "A string with a double quote (\") in it"
This string will create a problem as string will terminated at second  quotation in the middle of the string according to out definition of string group in above. For skipping \" we have to add information about skipping as following.
                      :syntax region xString start=/"/ skip=/\\"/ end=/"/ 

Nesting Items

Suppose you want to highlight TODO in big yellow latter even though it is highlighted blue in comment. To inform gvim/vim you should write the following command in command line of gvim/vim.
                    :syntax keyword xTodo TODO contained
                    :syntax match xComment /%.*/ contains=xTodo
The first gvim command line indicates that keyword can only exist in another syntax item. The next line   contains=xTodo indicates that xTodo syntax element is inside it. 

Recursive nesting   
Suppose x language defines code blocks in curly brackets. This code may contains another code block as follows. One example of the code is given below.
                          while(a>b) {
                                      while(x>y) {
                                                           printf("inside block");
                                                         }
                                             }
gvim/vim command for this type of recursive blocs is as follows.
                :syntax region xBlock start=/{/ end=/}/ contains=xBlock
In the above code first block starts with { in first line and second block starts in second line with {. Since we are inside a xBlock and the xBlock contains itself so the recursive block starts again. now in third line } is detected so nested block ends and then in fourth line top  block ends.


PREV PAGE                                             INDEX                                         NEXT PAGE

Saturday, March 23, 2013

configuring color property for highlight group

First of all to know how to get started with grouping and coloring that particular group read Previous Page.

You can change colors with :colorscheme command. This loads your gvim opened file wiht :highlight command as following.
                   :hi comment gui=bold
In this command all setting will not change only specified field will change and this settings are merged with old one. So after this command your result for color scheme setting for group comment will merge with existing setting only parameter gui becomes bold. When listing a highlight group and 'verbose' is non-zero, the listing will also display where it was last set. Example:
            :verbose hi Comment 
             Comment xxx term=bold ctermfg=4 guifg=Blue
               Last set from /home/mool/vim/vim7/runtime/syntax/syncolor.vim
When ":hi clear" is used then the script where this command is used will be mentioned for the default values.As above color property of group contains variables like term, ctermfg, guifg etc. We will discuss them.

 term/cterm/gui

     bold
  underline
undercurl not always available reverse inverse same as reverse italic standout NONE no attributes used (used to reset it)


you can set any property for your defined group for highlighting purpose.


ctermfg/ctermbg/guifg/guibg/guisp

This all variable has popular color value is as follow. It color name might change according to operating system and gvim version you are using.
     Red         LightRed        DarkRed
     Green       LightGreen      DarkGreen       SeaGreen
     Blue        LightBlue       DarkBlue        SlateBlue
     Cyan        LightCyan       DarkCyan
     Magenta     LightMagenta    DarkMagenta
     Yellow      LightYellow     Brown          DarkYellow
     Gray        LightGray       DarkGray
     Black       White
     Orange      Purple         Violet

you can see which variables are used for configuration of your gvim file highlighting by displaying property of any existing group.
Here I have given one example for creating group and assigning some particular value to that group.

                         :syntax keyword room sandip hitesh brijesh
by this command group will be created with name room. now using following command you can give your defined group a color property you want to give.
                          :hi room term=bold  gui=bold guifg=red 

If you are coding in suppose x programming language there must be a string in that. And string is always highlighted with different color which is in double inverted comma. For example "gvim and vim editor" . Now you might be thinking how to isolate word in string and normal word. Gvim/Vim has facility to identify those type of pasterns. That I have given in next blog that how to define complex group for highlighting in gvim/vim.



PREV PAGE INDEX NEXT PAGE


Configuration of magic box .gvimrc

I  know a little much about .vimrc file configuration. I have written something about it here. These features will make your gvim window comfortable to read.
The .gvimrc file is a file that is source by gvim software every time you open any file using gvim software. So if you want to set some setting permanently write down appropriate command by taking reference of the following discussion. Same as we have discussed in earlier post.


 Changing Background and font color

here is a simple command for using highlighting your gvim background and text. Simply  type command below to make your background of gvim Black and foreground (normal text color) white.
           :highlight Normal guibg=Black guifg=White
you can experiment on this command and it you like this setting you can write it in your .gvimrc file so that now onward your each and every window will open with Black background. You can write colors black,white,green,red etc. as per your requirements.
Creating groups for highlighting variable

The following commands creates perticular group of words. I have created one group of my roommates here by the following command.
          :syntax keyword room sandip hitesh brijesh
after creating this type of group you can link some property which might be given in your gvim package. The gvim software I am using has defined propery under name keyword and user can link property of keyword with defined group as follows.
               :highlight link room keyword
by this command above three words will have property same as keyword(related to highlighting in gvim).  So if in your gvim package if keyword is highlighted as bold & red color. Whenever you are typing "sandip" "brijesh"  or  "hitesh" these words becomes bold and red colored. You can see what property has been set for highlighting for any group.
             :highlight keywordThis command gives current highlighting setting for the word group keyword. Same way you can see settings for any other variable by following command.
             :highlight groupname  or :hi groupname
while using this command if group is linked to any other group it will show you that group name to which your group is linked.
Some more colors of background and foreground possible for gvim. 

         Here are some groups that has been defined in gvim package.
                *Comment any comment
        *Constant           any constant
        *Identifier         any variable name
        *Statement          any statement
        *PreProc generic    Preprocesso
        *Type               int, long, char, etc.
        *Special            any special symbol
        *Underlined         text that stands out, HTML links
                *Special                           any special symbol
        *Underlined         text that stands out, HTML links
        *Ignore             left blank, hidden  |hl-Ignore|
        *Error              any erroneous construct
        *Todo               anything that needs extra attention; mostly the keywords TODO FIXME and XXX


Now if you want to check which items are currently defined you can use following command:
           :syntax
To check which syntax items have currently been defined. This is quit useful when experimenting with syntax.  It also shows the colors used for each item, which helps to find out what is what.



MATCHING CASE
Some languages are not case sensitive, such as Pascal.  Others, such as C, are
case sensitive.  You need to tell which type you have with the following
commands:
 :syntax case match
 :syntax case ignore

The "match" argument means that Vim will match the case of syntax elements. Therefore, "int" differs from "Int" and "INT".  If the "ignore" argument is used, the following are equivalent: "Procedure", "PROCEDURE" and "procedure". 
   The ":syntax case" commands can appear anywhere in a syntax file and affect the syntax definitions that follow.  In most cases, you have only one ":syntax case" command in your syntax file; if you work with an unusual language that contains both case-sensitive and non-case-sensitive elements, however, you can scatter the ":syntax case" command throughout the file.



This command is for ignoring case is different from the earlier command :set ic that we have seen earlier.









 PREVIOUS PAGE              GO BACK TO INDEX                  NEXT PAGE

Friday, March 8, 2013

Processing Cases in gvim

In today's post I have tried to explain something about processing words in gvim related to upper case and lowercase conversion and usage. sometime you might want to convert some part of file into uppercase or lower case. This happens specially in declaration of variables. As we have to  follow company's codding guidelines this features of gvim becomes very much useful.


  • Converting line into upper case and lower case format
    . Here is the command to convert text into lowercase format. Simply press Vu by keeping your cursor on the line at which you want to convert case of the whole line's character to lower. And if you want it in uppercase format press VU. Or you can do this both processing on particular by remembering one single command.  g~~ This command will simply change the case of the line what ever it is.
  • Modifying case of the word in gvim
    As we can change the case of the line same way we can change the case of the word in gvim. This is as simple as for line. Keep your cursor on the word you want to change. Then press command vEU convert word into uppercase and same way vEu converts word into lower case.
  • Setting all case into upper case using gvim
    Setting all case in entire gvim opened file is easy. To set entire file into upper case format command is gggUG  and to convert entire gvim opened file into lower case if ggguG.
     
  • Ignoring case while searching in gvim file
    This might be most useful feature related to case. Imagine a situation you are view is log file of any code you have written and searching for error. This time it is quit possible you have written ERROR or Error or error or any other way with same spelling just case of the latter is changing.  In this case if you search ERROR by using command /ERROR other two pattern of writing error will not be hi-lighted. But  this can be achieved by following simple command.
                     :set ignorecase
    after typing this command gvim will ignore case sensitivity while searching inside gvim edited file. 
Here are some more command on case which might be useful for your work.

       :%s/\<./\u&/g    To set first latter of each word to uppercase format
       :%s/\<./|1&/g    To set first letter of each word to lowercase format
       :%s/.*/\u&        To set first letter of each line into uppercase format
       :%s/.*/\|&         To set first letter of each line into lowercase format

These four command processes entire gvim edited file.  But if you want to do this process of converting upper case and lowercase for particular selected lines you can do this by using s or range of line number in place of %s as we have earlier seen in commands related to search and replacing string in gvim file


                                                     GO BACK TO INDEX

Tuesday, March 5, 2013

INDEX FOR GVIM

You will be facinated after reading the following post. Gvim is really very much powerful software.

                                       Configuring .vimrc and .gvimrc for Mapping Keys

These four links are useful when you are using gvim first time or beginner to use gvim.


                                      define complex group for highlighting
 
                                      configuring color property for highlight group

                                      Configuration of .gvimrc


                                     Gvim Basics - 1

                                     Gvim Basics - 2

                                     Gvim Basics - 3

                                     Gvim Basics - 4


In the following links might be useful to use gvim very much efficiently. Techniques and commands given in the link will might save your time and effort from tedious editing process and speed up your productivity.

                                 Use gvim efficiently - 1

                                  Use gvim efficientlyc- 2

                                  Gvim FAQ

                                  Processing Cases in gvim

Note : If you have any questions regarding gvim please let me know through comment on this post I will try my best to give you an answer.

Monday, March 4, 2013

Gvim FAQ


  • How to search number in gvim file??
    If any text file contain digits it is in the range 0-9 We can use simple gvim command to find all digits in gvim edited file. As follows
                      /s/[0-9]
  • How to revert/undo action based on time?
    Gvim provides facility to revert your changes based on time this can be achieved by the following command??
            :earlier 50m           or            :earlier 5h
    using this command you can revert back to 50 min or 5 hours. This will be very much useful if you have done all things wrong for the day.
  • How to delete line containing  particular string?
    Sometimes while debugging you find that some lines in log is unnecessary and obstacle in your debugging. This can be solved by the following command.
               :g/gvim_line_to_delete/d 
    Command deletes all lines containing string gvim_line_to_delete
    some time you might want particular lines and delete all other. This can be achieved by the following command.
                :v/gvim_line_to_keep/d
    Command deletes all line which does not contain gvim_line_to_keep.
  • How to jump at particular line directly?
    when you compile a code first time after writting always there is a compilation error.(Whenever I do not get error I doubt myself) compiler shows you the line number at which error is. If you have written code of 3000 line you will get tired by scrolling. But in gvim you can directly go to particular line by the following command.
               :gvim_line_num
    thus if you want to go to 245 th line simply write command :245 and your cursor is moved to that line. As we have seen $ indicates end of something. :$ command moves your cursor at last line of your file. 

                                                       GO BACK TO INDEX

Gvim Basics - 4

In previous we have discussed some basic commands that is useful and enough for editing with gvim. He I have tried to give some more functions of gvim so that you can use it more vigorously.


  • Searching and replacing in entire file using gvim 
    Searching and replacing is as easy as searching file. The command for it is as follows
            :%s/old_gvim/new_gvim/gHere  %s shows this search operation should be performed on entire file. Here g indicates that operation should be performed on each occurrence in a line. If you want gvim should ask you or I can say precisely confirm before each replacement you can add c at the end of the command. For this operation command is as follows.
             :%s/old_gvim/new_gvim/gcThis command search and replace any keyword in entire file but confirm from user about replacement task. User have to press for yes and n for no. If you want to perform this replacing operation you can do it many ways some of these was that I know is shown here. First select line by the methods discribed in previos blog. Then press : and you command line will become as follows
              :'<,'>Then type above commands without using % in it. Your final command for repacement in selected text is
                :'<,'>s/old_gvim/new_gvim/gc
                :'<,'>s/old_gvim/new_gvim/g

    You can also give line numbers in which you want to perform search and replace operatio in gvim. The command,
                :20,40s/old_gvim/new_gvim/gc
    this command will replace old_gvim with new_gvim if it is occuring in between lin number 20 to 40. same way,
                :20,$s/old_gvim/new_gvim/gc
    As we know normally $ is used to represent end of something. Same way here this commnd performs that replacment operation on line number 20 to entire file or till the end of the file.


    Just for chang lets see some different functionality other than replace in gvim. Suppose you want to know how many times certain keyword is repeating your gvim edited file. This can be achieved by the command as follows
             :%s/search_string/&/gthis command will search all occurrence of the search_string in the entire file.
For advanced use of the gvim I have written a little about advanced use of gvim for beginners like me.
Use Gvim Efficiently , Using gvim Efficiently-2


                                                        GO BACK TO INDEX

Sunday, March 3, 2013

Gvim Basics - 3

In this page I have tried to cover other unique features of gvim.  These feature or command will help you to use this software more efficiently and robustly.

  • Undo and Redo action in gvim
    Undoing your action and redoing action is the simplest thing to do in gvim. Just first go into command mode and type u if you want to undo your editing action in gvim. And it you want to redo your action press control + r  and it is done.
  • Opening new tab in same gvim window
    Opening new tab in same window can be achieved by simply typing tabnew in command window. And then you can open your file. If you know the path of the file you can type path of the file to be edited in front of the :tabnew  command and directly open the file.
  • Opening file in same gvim window
    You can achieve this task by using command :e. If you are not giving the file path you want to edit in gvim your current file you are editing will be reloaded or reopened in the same window.  And by using command :E you can list down all file or directory in current directory in gvim window. You do not need to go into command window and open file from there. Now you can open file just by moving cursor at that file and pressing enter at that file.
  • Auto completing the keyword in gvim 
    This is the most fascinating feature of the gvim I  have found. To auto complete the word you are typing just press control + p after typing some initial character of the keyword and gvim will list down all keywords matching with the initial you have typed in the current window.
  • Displaying line numbers and ignoring the case sensitivity
    You can display line numbers of the each and every line by typing command :set nu and gvim will show each line number. It is by default that while you are searching the any keyword gvim is case sensitive. If you want to make it ignore that case sensitivity you can type command :set ic . This will set ignore case and gvim will ignore case sensitivity while searching keyword in file.
  • Searching begin's respective end and end's respective begin
    This can be achieved by pressing shift + 5  command while your cursor is at any character of the begin or end. If your cursor is on begin gvim will  find it's respective end. If it is at end gvim will find its respective begin. This feature is very much useful while you are codding large program and there is large hierarchy.
  • Splitting window/tab in one or more part
    By pressing command :sp command you can split your file into another file. So you can edit two or more file at the same time. By giving path of the file you can also open file in split format. This is very much useful feature of the gvim. 


                                                GO BACK TO INDEX

Saturday, March 2, 2013

Gvim basics-2

In this page I have tried to cover selection of text, copying, delete, paste and searching some keyword  using gvim text editor. And all this functions is done without touching mouse.

  • Selecting the text in gvim 
    There are main three methods that I know using which you can select some text in you gvim file. There might be so many other methods. 1) First is go to the character place from where you want to select text in the gvim file. Then press v and now by moving your cursor up,down,left or right from keyboard you can select text. 2) In second type of selection go to the line which you want to select then press shift + v and then by pressing up or down arrow in your keyboard you can select lines which you want to process. 3) The third method is control + V  now by moving your arrow up or down you can select your text in gvim editor file.
    All three methods seem same but you will find and advantage of using each methods once you will start using it.
  • Copying text in gvim/vim
    You can copy text using y command once have selected your desired text. Here y indicates action yank. Simply google yank and you will find it why they have chosen y for copying. It is also possible to copy some lines even if you have not selected any line in gvim editor. This command is yy
    You can copy the line at which cursor is by simply pressing command yy. Or you also can specify how many lines you want to copy without selecting those lines and then press yy . Suppose you want to copy your current line and 7 lines below current line. Do not need to first select those lines and than copy it. You can directly select those 8 line by pressing first 8 and next to it yy .
    Once you have copied text in clipboard you have to just press p in command mode and it is done for peasting it.
  • Deleting or cuting text in gvim/vim
    Deleting some text from file edited in gvim is as simple as copying. First select your text in gvim editor you want to delete. Then press d  in command line and it is done. One thing you should keep in mind is that while you are deleting some text it stores in gvim's clipboard so if you want to pest it some where else you can do it.
    Same as copying you can delete current line at which your cursor is can be deleted by pressing dd and current line is deleted  or I can say that line is completely removed form your gvim editor text. If you want to delete say 10 lines you can simply press 10 and press dd  same as copying 10 lines.
    As I said text we are deleting remain stored into the clipboard of gvim till next delete or copy operation is performed so you can paste any where you want.

  • Searching keyword in file edited in gvim/vim
    Searching specific key word in gvim is very much easy task to do. You need to be in command mode by pressing Esc. And after that type " / "  and then type your keyword you want to search. Suppose you want to search keyword "gvim" in the file that you are editing. For this type the following command in your command line.
                /gvim
    and press Enter and your cursor will move to the matched keyword. You can go to next matching keyword by pressing n .  If you want to search forward in the file press n  and if you want to search backward in the file press N . Another way for searching keyword is move your cursor to the keyword and press *(as-trick) you can find another similar word. currently you might not find advantage in searching forward or backward but it is very much useful while you are editing large program code that might contain 2000 lines.
Up till now we have seen the commands that will replace your habit of using notepad or any other GUI editor. You will also see how much it is easy and fast to use gvim for editing files. In next link we will see some more features of gvim. (or I can say more reasons to use it)
          http://gvimeditor.blogspot.in/2013/03/gvim-basics-3.html

Friday, March 1, 2013

Gvim Basics


  1. Introduction to gvim 

Gvim is very much efficient for developers. It is command base editor. The difference between vim and gvim is that gvim is gui version of unix editor vim. gvim has nice gui control with hi-lighting facility.

You can download gvim form url www.vim.org or you can simply search on google it is easily available.

Let's gets start with gvim. First of all we will start with the configuration of gvim.

2.1 Configuration gvim

Gvim is configured by .vimrc or .gvimrc file in linux system. While for windows system this file name is _vimrc file. For linux no need to do anything if you have created the file just copy it in home folder and restart your gvim again and you are opening file with new configuration.

set nocompatible " Use gVim defaults

" set tw=80   tw to specify a default text width
set fo=tcrq  " fo to specify default formatoptions
   " t auto-wraps text using textwidth
   " c auto-wraps comments using textwidth
   " r auto-inserts the current comment leader
   " q allows formatting of comments

   " allow backspacing over everything in insert mode
   set backspace=2

set tabstop=1           " Each Tab has 1_spaces equivalent width
set shiftwidth=2        " Indentation width when using >> and << re-indentation
set nobackup
set expandtab           " Tabs are expanded to spaces

 here example for .vimrc is givm. This I have checked in linux system only.

2.2   Gvim modes

Gvim is model editor it has two modes of operation for editing files 1) insert mode 2) qcommand mode
There might be other mode for using it but for beginners this two is enough
      **) Insert mode
  Once you have started gvim by default you are in command mode. To enter from command mode to insert mode press character "i" and you will be in insert mode. Edit files as per you want to edit it and than press Esc for getting into command mode
      **) Command mode
    Command mode is the most important part of gvim. Or I can say command mode is the only advantage of gvim. By pressing Esc you can get into command mode of gvim. Then write commands
":" and write your required command for process like cut,copy, highlight etc.

For beginners I have listed down some commands that will be very much useful.

3. Gvim basic commands

  •  a ,  i
    Both of these command is used for entering into insert mode. The difference between them is  when we use "i" cursor is placed before character while using "a" cursor is placed at the end of the charecter.
  • :w
    Once you have written or entered text in the file you are editing in gvim. You have to save it before you quit the file. You can do it by simply writing command :w and it is written inside hard drive.
  • :quit , :q
    Once you have edited file in gvim. :q command is used for quitting the file. This command will not work if you have not saved the changes. And to ignore the changes you can use the command ":q!" command this command will close the file with ignoring the changes made in the file.
  • :wq , wa, wqa , qa
    All these four commads are the combination of the w, q and a(here a for all) :wq command writes  and quit file you are editing in gvim. :wa command saves all files that are currently open in the window. Same way :qa command quits all files open in the window(again :qa will work only if you have saved all files being edited in gvim's current window). And in the last my favorite command   when I am leaving my office in hurry is :wqa. This command writes and quits all the files that is being edited currently in gvim.


    These are four basic commands that is needed when you are using gvim first time. Another commands for gvim editor I have given at following page as this page is getting too long according to my  view.
    http://gvimeditor.blogspot.in/2013/03/gvim-basics-2.html



                                                   GO BACK TO INDEX

Wednesday, February 27, 2013

Use gvim efficiently-2

**) Open different files in same window with different tabs

Sometimes you write two or more filenames in front of gvim command  and find that those files are open but you have to writ :n or :N command each time you want to switch from one file to another.

In this case to can open different file in different tabs in same window by using the following command.
    gvim -p file1.sv file2.sv
and its done.

 **) adding same text in multiple lines using gvim

suppose one file having following text is edited in gvim.

   bit  var1 ;
   bit  var2 ;
   bit  var3 ;
   bit  var4 ;
you want to add [31:0] in front of variable name in each line. NO NEED TO ADD EACH AND EVERY LINE IF YOU ARE USING gvim.
jist press cntr+v  keeping courser  ant 4th place of 1st line. then reach to 4th line vertically. Now you have selected one-one place in each line. Press shift+i and write text [31:0]. Then press Esc. And you have done it. This is the most amazing feature of gvim I have found. I am sure you will like it.

**) Make some tedious editing easy using gvim

Suppose you want to repeat some editing  wile editing file. Your last editing step is always recorded in your gvim buffer.

add_              _data      ad_dr         aw_len
if you want add "gvim " at the places where _ is given.
--> press Esc and go to that place of edting. Press "i" to move into insert mode. Then type "gvim"  at that place than type Escp. Then goto "_" in second word. Then press "." and its done. As gvim stores last action and by press sing . it is repeated you do not need to write four times "gvim".



                                                      GO BACK TO INDEX

Tuesday, February 26, 2013

Use gvim efficiently

I am fascinated by the feature of gvim/vim. Once you become addicted by it, it's hard to switch to other editor.  Below I have mentioned some techniques using which you can increase your speed of using this amazing command line software.

1)  Running default command

You might have set number of each lines in your edited files in gvim/vim. Or you might be using ignore cases. For this  you have to type command "set num" or "set ic"  every time you open any file. Right ??
But if you are using gvim/vim in linux you can avoid  this tedious process by making one file in your home dir.
make one file name .vimrc and write each command you want. For example you want to highlight line number every time.

make file with name .vimrc

Than writ following command in that file

          set num
          set ic

 you can add whichever command you want in this file.
What happens is that whenever you start gvim/vim these command are automatically executed every time in gvim/vim's command line.


2) Adding abbreviation

Programmer needs to write some syntax frequently. Suppose you want to print something than below syntax in unavoidable.
        $display("");
Each time whenever you want to print something you have to write this syntax.
You can create abbreviation as $d as follows in your  .vimrc file.
       ab $d $display(""); 
  now whenever you want to write $display you can write
     $d  and press Esc. and its done!!!
you can create as many abbreviation as you want. If in you want to add newline between some tax in abbreviation you can you <CR> as shown in the last line of my .vimrc file.

3) Creating aliases in gvim/vim

If you do not like to type  "tabnew" to open new tab in the window? And want some shortcut like t. Than here is the solution. Yes you can create alias using .vimrc file.

just put  write the following line in your .vimrc file as follows.

  cabbrev t tabnew

And it is done. Now next time you open gvim/vim and want to open newtab just write "t" command  in gvim/vim's command line and new line is opened.


Here I have given My .vimrc file

set number
cabbrev t tabnew
ab $d $display("sandip : ");
ab axidebug `sib_axi_report_debug(log,msg_id,$psprintf(""));
ab axiinfo `sib_axi_report_info(log,msg_id,$psprintf(""));
ab ahbdebug `sib_ahb_report_debug(log,msg_id,$psprintf(""));
ab ahbinfo `sib_ahb_report_info(log,msg_id,$psprintf(""));
ab b begin<CR><CR>end



                                                      GO BACK TO INDEX