Monday, March 4, 2013

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

No comments:

Post a Comment