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

No comments:

Post a Comment