Tuesday, October 20, 2015

Spelling check in gvim

I am very poor at English spelling. Usually nobody give any attention to spelling of your code. Means what name you are giving to your variable. But when it comes to comments and print message suddenly people starts noticing that you have written this spelling incorrect. 

Gvim has a facility for spell checking. Use below simple command to enable spelling check feature or write down same in .gvimrc file to enable it every time you open gvim editor. 

 set spell

Sunday, July 27, 2014

Cool things to learn about gvim

Change gvim/vim directory in that file is in. 

This is very useful thing when you are working in project which contains very large number of directory. In this case sometimes when you use tabnew command directory in which newtab is opened is the directory at which you previously run gvim command on terminal. Let's take an example,

Suppose you have written following command to open file.
You are in current directory asdfg
  gvim a/b/c/d/e/f.txt

Now in gvim tabnew command which will open new tab which will have current directory asdfg and you have to again write whole path a/b/c/d/e and then you will be able to open your file.

Now what if your tabnew command considers your current directory as instead of asdfg ?? 
Wont it will be cool thing ??
You can do this using command :cd %:p:h 
 Whole procedure is like this :
  write :cd %:p:h and then tabnew ./ your current directory is now.You are done !!!!!



Previous                                Index     

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