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 y 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