0

Is there a way to use wildcards in gedit's search and replace function? I really don't want to have to install anything or try or have to figure out how to use a 3rd party plugin—I installed the advanced find and replace plugin, yet there is absolutely zero information on how to use the thing.

  • what plugin it is ? – Raja G Oct 05 '13 at 01:29
  • See http://askubuntu.com/questions/173785/install-regex-plugin-for-gedit. As for how to use it, there are two fields, search and replace and standard regex applies. –  Oct 05 '13 at 01:53

1 Answers1

3

Taking your question literally, there is a ridiculous/extreme way to enable wildcards without installing any additional plugins.

  1. First, go to edit/preferences/plugins and enable the python console. This plugin should be installed by default.
  2. Hit ctrl-f9 to open the bottom panel and expose the console
  3. Paste the following code into the console and hit enter:

    #function to replace stuff
    import re
    def replace(re1,re2):
        doc = window.get_active_document()
        start, end = doc.get_bounds()
        txt = start.get_slice(end)      
        newtxt = re.sub(re1,re2,txt)    
        doc.set_text(newtxt)
    
  4. For demo purposes, paste the above code into your gedit document

  5. Now, from the console, you can use regular expressions with wildcards like so: replace(r'function.*',r'new comment')

Pretty fun, right? :)

MattY
  • 401
  • 3
  • 8